ZQuest Classic Coverage Report


Directory: src/
File: src/zc/zc_sys.cpp
Date: 2025-09-03 02:14:11
Exec Total Coverage
Lines: 1991 4574 43.5%
Functions: 127 337 37.7%
Branches: 1345 3764 35.7%

Line Branch Exec Source
1 #include "zc/zc_sys.h"
2
3 #include "allegro/gfx.h"
4 #include "allegro/gui.h"
5 #include "allegro/inline/draw.inl"
6 #include "allegro5/joystick.h"
7 #include "base/files.h"
8 #include "base/render.h"
9 #include "base/zdefs.h"
10 #include "zalleg/zalleg.h"
11 #include "base/qrs.h"
12 #include "base/dmap.h"
13 #include <functional>
14 #include <queue>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <cstring>
18 #include <math.h>
19 #include <map>
20 #include <filesystem>
21 #include <ctype.h>
22 #include <sstream>
23 #include "base/version.h"
24 #include "base/zc_alleg.h"
25 #include "gamedata.h"
26 #include "zc/frame_timings.h"
27 #include "zc/replay_upload.h"
28 #include "zc/zc_init.h"
29 #include "init.h"
30 #include "zc/replay.h"
31 #include "zc/cheats.h"
32 #include "zc/render.h"
33 #include "base/zc_math.h"
34 #include "base/zapp.h"
35 #include "dialog/cheatkeys.h"
36 #include "metadata/metadata.h"
37 #include "zc/zelda.h"
38 #include "zc/saves.h"
39 #include "tiles.h"
40 #include "base/colors.h"
41 #include "pal.h"
42 #include "base/zsys.h"
43 #include "base/qst.h"
44 #include "zc/zc_sys.h"
45 #include "play_midi.h"
46 #include "gui/jwin_a5.h"
47 #include "base/jwinfsel.h"
48 #include "base/gui.h"
49 #include "midi.h"
50 #include "subscr.h"
51 #include "zc/maps.h"
52 #include "sprite.h"
53 #include "zc/guys.h"
54 #include "zc/hero.h"
55 #include "zc/title.h"
56 #include "particles.h"
57 #include "sound/zcmusic.h"
58 #include "zc/ffscript.h"
59 #include "dialog/info.h"
60 #include "dialog/alert.h"
61 #include "zc/combos.h"
62 #include "zc/jit.h"
63 #include "zc/zc_subscr.h"
64 #include <fmt/format.h>
65 #include "zconsole/ConsoleLogger.h"
66 #include "zinfo.h"
67 #include "base/misctypes.h"
68 #include "music_playback.h"
69 #include "base/new_menu.h"
70 #include "base/files.h"
71 #include "iter.h"
72
73 #ifdef __EMSCRIPTEN__
74 #include "base/emscripten_utils.h"
75 #endif
76
77 using namespace std::chrono_literals;
78
79 extern bool Playing;
80 int32_t sfx_voice[WAV_COUNT];
81 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c);
82 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c);
83
84 static ALLEGRO_JOYSTICK* gamepad_dlg_cur_joystick;
85 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c);
86
87 extern byte monochrome_console;
88
89 extern sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations;
90 extern std::string loadlast;
91 extern char *sfx_string[WAV_COUNT];
92 byte use_dwm_flush;
93 byte use_save_indicator;
94 int32_t paused_midi_pos = 0;
95 byte midi_suspended = 0;
96 byte zc_192b163_warp_compatibility;
97 bool epilepsyFlashReduction;
98 signed char pause_in_background_menu_init = 0;
99 byte pause_in_background = 0;
100 bool is_sys_pal = false;
101 static bool load_control_called_this_frame;
102 extern PALETTE* hw_palette;
103 extern bool update_hw_pal;
104 extern const char* dmaplist(int32_t index, int32_t* list_size);
105 int32_t getnumber(const char *prompt,int32_t initialval);
106
107 extern bool kb_typing_mode; //script only, for disbaling key presses affecting Hero, etc.
108 extern int32_t cheat_modifier_keys[4]; //two options each, default either control and either shift
109
110 #ifdef ALLEGRO_LINUX
111 static const char *samplepath = "samplesoundset/patches.dat";
112 #endif
113 char qst_files_path[2048];
114
115 extern TopMenu the_player_menu;
116 #ifdef _MSC_VER
117 #define getcwd _getcwd
118 #endif
119
120 bool rF11();
121 bool rI();
122 bool rQ();
123 bool zc_key_pressed();
124
125 #ifdef _WIN32
126
127 // This should only be necessary for MinGW, since it doesn't have a dwmapi.h. Add another #ifdef if you like.
128 extern "C"
129 {
130 typedef HRESULT(WINAPI *t_DwmFlush)();
131 typedef HRESULT(WINAPI *t_DwmIsCompositionEnabled)(BOOL *pfEnabled);
132 }
133
134 void do_DwmFlush()
135 {
136 static HMODULE shell = LoadLibrary("dwmapi.dll");
137
138 if(!shell)
139 return;
140
141 static t_DwmFlush flush=reinterpret_cast<t_DwmFlush>(GetProcAddress(shell, "DwmFlush"));
142 static t_DwmIsCompositionEnabled isEnabled=reinterpret_cast<t_DwmIsCompositionEnabled>(GetProcAddress(shell, "DwmIsCompositionEnabled"));
143
144 BOOL enabled;
145 isEnabled(&enabled);
146
147 if(isEnabled)
148 flush();
149 }
150
151 #endif // _WIN32
152
153 313 void zc_exit(int code)
154 {
155 extern CConsoleLoggerEx zscript_coloured_console;
156
157 313 set_is_exiting();
158
159
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if (replay_get_mode() == ReplayMode::Record) replay_save();
160 313 replay_stop();
161 313 music_stop();
162 313 kill_sfx();
163
164
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 305 times.
313 if (get_qr(qr_OLD_SCRIPT_VOLUME))
165 {
166 //restore user volume settings
167
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
168 {
169 1 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
170 1 }
171
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
172 {
173 1 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
174 1 }
175
2/2
✓ Branch 0 taken 304 times.
✓ Branch 1 taken 1 times.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
176 {
177 1 emusic_volume = (int32_t)FFCore.usr_music_volume;
178 1 }
179
1/2
✓ Branch 0 taken 305 times.
✗ Branch 1 not taken.
305 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
180 {
181 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
182 }
183 305 }
184
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
185 {
186 pan_style = (int32_t)FFCore.usr_panstyle;
187 }
188 313 save_game_configs();
189
190 313 zscript_coloured_console.kill();
191 313 jit_shutdown();
192 313 frame_timings_end();
193 313 quit_game();
194
195 313 Z_message("ZQuest Classic website: https://zquestclassic.com\n");
196 313 Z_message("ZQuest Classic docs: https://docs.zquestclassic.com\n");
197
198 313 allegro_exit();
199 313 exit(code);
200 }
201
202 93594 bool flash_reduction_enabled(bool check_qr)
203 {
204
4/4
✓ Branch 0 taken 88914 times.
✓ Branch 1 taken 4680 times.
✓ Branch 2 taken 87624 times.
✓ Branch 3 taken 92304 times.
93594 return (check_qr && get_qr(qr_EPILEPSY)) || epilepsyFlashReduction || replay_is_debug();
205 }
206
207 // Dialogue largening
208 void large_dialog(DIALOG *d)
209 {
210 large_dialog(d, 1.5);
211 }
212
213 void large_dialog(DIALOG *d, float RESIZE_AMT)
214 {
215 if(!d[0].d1)
216 {
217 d[0].d1 = 1;
218 int32_t oldwidth = d[0].w;
219 int32_t oldheight = d[0].h;
220 int32_t oldx = d[0].x;
221 int32_t oldy = d[0].y;
222 d[0].x -= int32_t(d[0].w/RESIZE_AMT);
223 d[0].y -= int32_t(d[0].h/RESIZE_AMT);
224 d[0].w = int32_t(d[0].w*RESIZE_AMT);
225 d[0].h = int32_t(d[0].h*RESIZE_AMT);
226
227 for(int32_t i=1; d[i].proc !=NULL; i++)
228 {
229 // Place elements horizontally
230 double xpc = ((double)(d[i].x - oldx) / (double)oldwidth);
231 d[i].x = int32_t(d[0].x + (xpc*d[0].w));
232
233 if(d[i].proc != d_stringloader)
234 {
235 if(d[i].proc==d_bitmap_proc)
236 {
237 d[i].w *= 2;
238 }
239 else d[i].w = int32_t(d[i].w*RESIZE_AMT);
240 }
241
242 // Place elements vertically
243 double ypc = ((double)(d[i].y - oldy) / (double)oldheight);
244 d[i].y = int32_t(d[0].y + (ypc*d[0].h));
245
246 // Vertically resize elements
247 if(d[i].proc == jwin_edit_proc || d[i].proc == jwin_check_proc || d[i].proc == jwin_checkfont_proc)
248 {
249 d[i].h = int32_t((double)d[i].h*1.5);
250 }
251 else if(d[i].proc == jwin_droplist_proc || d[i].proc == d_joylist_proc)
252 {
253 d[i].y += int32_t((double)d[i].h*0.25);
254 d[i].h = int32_t((double)d[i].h*1.25);
255 }
256 else if(d[i].proc==d_bitmap_proc)
257 {
258 d[i].h *= 2;
259 }
260 else d[i].h = int32_t(d[i].h*RESIZE_AMT);
261
262 // Fix frames
263 if(d[i].proc == jwin_frame_proc)
264 {
265 d[i].x++;
266 d[i].y++;
267 d[i].w-=4;
268 d[i].h-=4;
269 }
270 }
271 }
272
273 for(int32_t i=1; d[i].proc!=NULL; i++)
274 {
275 if(d[i].proc==jwin_slider_proc)
276 continue;
277
278 // Bigger font
279 bool bigfontproc = (d[i].proc != d_midilist_proc && d[i].proc != jwin_droplist_proc && d[i].proc != jwin_abclist_proc && d[i].proc != jwin_list_proc && d[i].proc != d_joylist_proc);
280
281 if(!d[i].dp2 && bigfontproc)
282 {
283 d[i].dp2 = get_zc_font(font_lfont_l);
284 }
285 else if(!bigfontproc)
286 {
287 ((ListData *)d[i].dp)->font = &a4fonts[font_lfont_l];
288 }
289
290 // Make checkboxes work
291 if(d[i].proc == jwin_check_proc)
292 d[i].proc = jwin_checkfont_proc;
293 else if(d[i].proc == jwin_radio_proc)
294 d[i].proc = jwin_radiofont_proc;
295 }
296
297 jwin_center_dialog(d);
298 }
299
300 static char cfg_sect[] = "zeldadx"; //We need to rename this.
301 static char ctrl_sect[] = "Controls";
302 static char sfx_sect[] = "Volume";
303
304 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
305 {
306 return D_O_K;
307 }
308
309 bool is_reserved_key(int c)
310 {
311 switch(c)
312 {
313 case KEY_ESC:
314 return true;
315 }
316 return false;
317 }
318 bool is_reserved_keycombo(int c, int modflag)
319 {
320 if(c==KEY_F4 && (modflag&KB_ALT_FLAG))
321 return true;
322 return false;
323 }
324 bool checkcheat(Cheat cheat)
325 {
326 if(cheatkeys[cheat][0] && zc_readkey(cheatkeys[cheat][0]))
327 return true; //Main key pressed
328 if(cheatkeys[cheat][1] && zc_readkey(cheatkeys[cheat][1]))
329 return true; //Alt key pressed
330 return false;
331 }
332 313 void load_default_cheatkeys()
333 {
334 313 memset(cheatkeys, 0, sizeof(cheatkeys));
335 313 cheatkeys[Cheat::Life][0] = KEY_H;
336 313 cheatkeys[Cheat::Life][1] = KEY_ASTERISK;
337 313 cheatkeys[Cheat::Magic][0] = KEY_M;
338 313 cheatkeys[Cheat::Magic][1] = KEY_SLASH_PAD;
339 313 cheatkeys[Cheat::Rupies][0] = KEY_R;
340 313 cheatkeys[Cheat::Bombs][0] = KEY_B;
341 313 cheatkeys[Cheat::Arrows][0] = KEY_A;
342 313 cheatkeys[Cheat::Clock][0] = KEY_I;
343 313 cheatkeys[Cheat::Walls][0] = KEY_F11;
344 313 cheatkeys[Cheat::Fast][0] = KEY_Q;
345 313 cheatkeys[Cheat::Light][0] = KEY_L;
346 313 cheatkeys[Cheat::IgnoreSideView][0] = KEY_V;
347 313 cheatkeys[Cheat::Kill][0] = KEY_K;
348 313 cheatkeys[Cheat::GoTo][0] = KEY_G;
349 313 cheatkeys[Cheat::TrigSecrets][0] = KEY_S;
350 313 cheatkeys[Cheat::ShowL0][0] = KEY_0;
351 313 cheatkeys[Cheat::ShowL1][0] = KEY_1;
352 313 cheatkeys[Cheat::ShowL2][0] = KEY_2;
353 313 cheatkeys[Cheat::ShowL3][0] = KEY_3;
354 313 cheatkeys[Cheat::ShowL4][0] = KEY_4;
355 313 cheatkeys[Cheat::ShowL5][0] = KEY_5;
356 313 cheatkeys[Cheat::ShowL6][0] = KEY_6;
357 313 cheatkeys[Cheat::ShowFFC][0] = KEY_7;
358 313 cheatkeys[Cheat::ShowSprites][0] = KEY_8;
359 313 cheatkeys[Cheat::ShowWalkability][0] = KEY_W;
360 313 cheatkeys[Cheat::ShowEffects][0] = KEY_E;
361 313 cheatkeys[Cheat::ShowOverhead][0] = KEY_O;
362 313 cheatkeys[Cheat::ShowPushblock][0] = KEY_P;
363 313 cheatkeys[Cheat::ShowHitbox][0] = KEY_C;
364 313 cheatkeys[Cheat::ShowFFCScripts][0] = KEY_F;
365 313 }
366
367 static bool loaded_game_configs;
368
369 313 void load_game_configs()
370 {
371 313 loaded_game_configs = true;
372 313 joystick_index = zc_get_config(ctrl_sect,"joystick_index",0);
373 313 js_stick_1_x_stick = zc_get_config(ctrl_sect,"js_stick_1_x_stick",0);
374 313 js_stick_1_x_axis = zc_get_config(ctrl_sect,"js_stick_1_x_axis",0);
375 313 js_stick_1_x_offset = zc_get_config(ctrl_sect,"js_stick_1_x_offset",0) ? 128 : 0;
376 313 js_stick_1_y_stick = zc_get_config(ctrl_sect,"js_stick_1_y_stick",0);
377 313 js_stick_1_y_axis = zc_get_config(ctrl_sect,"js_stick_1_y_axis",1);
378 313 js_stick_1_y_offset = zc_get_config(ctrl_sect,"js_stick_1_y_offset",0) ? 128 : 0;
379 313 js_stick_2_x_stick = zc_get_config(ctrl_sect,"js_stick_2_x_stick",1);
380 313 js_stick_2_x_axis = zc_get_config(ctrl_sect,"js_stick_2_x_axis",0);
381 313 js_stick_2_x_offset = zc_get_config(ctrl_sect,"js_stick_2_x_offset",0) ? 128 : 0;
382 313 js_stick_2_y_stick = zc_get_config(ctrl_sect,"js_stick_2_y_stick",1);
383 313 js_stick_2_y_axis = zc_get_config(ctrl_sect,"js_stick_2_y_axis",1);
384 313 js_stick_2_y_offset = zc_get_config(ctrl_sect,"js_stick_2_y_offset",0) ? 128 : 0;
385 313 analog_movement = (zc_get_config(ctrl_sect,"analog_movement",1));
386
387 //cheat modifier keya
388 313 cheat_modifier_keys[0] = zc_get_config(ctrl_sect,"key_cheatmod_a1",KEY_ZC_LCONTROL);
389 313 cheat_modifier_keys[1] = zc_get_config(ctrl_sect,"key_cheatmod_a2",0);
390 313 cheat_modifier_keys[2] = zc_get_config(ctrl_sect,"key_cheatmod_b1",KEY_ZC_RCONTROL);
391 313 cheat_modifier_keys[3] = zc_get_config(ctrl_sect,"key_cheatmod_b2",0);
392
393 //cheat keys
394 313 load_default_cheatkeys();
395 char buf[256];
396
2/2
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 11268 times.
11581 for(size_t q = 1; q < Cheat::Last; ++q)
397 {
398
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 if(!bindable_cheat((Cheat)q)) continue;
399 11268 std::string cheatname = cheat_to_string((Cheat)q);
400
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 util::lowerstr(cheatname);
401 11268 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
402
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 cheatkeys[q][0] = zc_get_config(ctrl_sect,buf,cheatkeys[q][0]);
403 11268 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
404
1/2
✓ Branch 0 taken 11268 times.
✗ Branch 1 not taken.
11268 cheatkeys[q][1] = zc_get_config(ctrl_sect,buf,cheatkeys[q][1]);
405 11268 }
406
407
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if((uint32_t)joystick_index >= MAX_JOYSTICKS)
408 joystick_index = 0;
409
410 313 Akey = zc_get_config(ctrl_sect,"key_a",KEY_Z);
411 313 Bkey = zc_get_config(ctrl_sect,"key_b",KEY_X);
412 313 Skey = zc_get_config(ctrl_sect,"key_s",KEY_ENTER);
413 313 Lkey = zc_get_config(ctrl_sect,"key_l",KEY_Q);
414 313 Rkey = zc_get_config(ctrl_sect,"key_r",KEY_W);
415 313 Pkey = zc_get_config(ctrl_sect,"key_p",KEY_SPACE);
416 313 Exkey1 = zc_get_config(ctrl_sect,"key_ex1",KEY_A);
417 313 Exkey2 = zc_get_config(ctrl_sect,"key_ex2",KEY_S);
418 313 Exkey3 = zc_get_config(ctrl_sect,"key_ex3",KEY_D);
419 313 Exkey4 = zc_get_config(ctrl_sect,"key_ex4",KEY_C);
420
421 313 DUkey = zc_get_config(ctrl_sect,"key_up", KEY_UP);
422 313 DDkey = zc_get_config(ctrl_sect,"key_down", KEY_DOWN);
423 313 DLkey = zc_get_config(ctrl_sect,"key_left", KEY_LEFT);
424 313 DRkey = zc_get_config(ctrl_sect,"key_right",KEY_RIGHT);
425
426 313 Abtn = zc_get_config(ctrl_sect,"btn_a",2);
427 313 Bbtn = zc_get_config(ctrl_sect,"btn_b",1);
428 313 Sbtn = zc_get_config(ctrl_sect,"btn_s",10);
429 313 Mbtn = zc_get_config(ctrl_sect,"btn_m",9);
430 313 Lbtn = zc_get_config(ctrl_sect,"btn_l",5);
431 313 Rbtn = zc_get_config(ctrl_sect,"btn_r",6);
432 313 Pbtn = zc_get_config(ctrl_sect,"btn_p",12);
433 313 Exbtn1 = zc_get_config(ctrl_sect,"btn_ex1",7);
434 313 Exbtn2 = zc_get_config(ctrl_sect,"btn_ex2",8);
435 313 Exbtn3 = zc_get_config(ctrl_sect,"btn_ex3",4);
436 313 Exbtn4 = zc_get_config(ctrl_sect,"btn_ex4",3);
437
438 313 DUbtn = zc_get_config(ctrl_sect,"btn_up",13);
439 313 DDbtn = zc_get_config(ctrl_sect,"btn_down",14);
440 313 DLbtn = zc_get_config(ctrl_sect,"btn_left",15);
441 313 DRbtn = zc_get_config(ctrl_sect,"btn_right",16);
442
443 313 epilepsyFlashReduction = zc_get_config(cfg_sect,"epilepsy_flash_reduction",0);
444
445 313 midi_volume = zc_get_config(sfx_sect,"midi",255);
446 313 sfx_volume = zc_get_config(sfx_sect,"sfx",255);
447 313 emusic_volume = zc_get_config(sfx_sect,"emusic",255);
448 313 pan_style = zc_get_config(sfx_sect,"pan",1);
449 313 volkeys = zc_get_config(sfx_sect,"volkeys",0)!=0;
450 313 zc_vsync = zc_get_config(cfg_sect,"vsync",0);
451 313 Throttlefps = zc_get_config(cfg_sect,"throttlefps",1)!=0;
452 313 Maxfps = zc_get_config(cfg_sect,"maxfps",0);
453 313 TransLayers = zc_get_config(cfg_sect,"translayers",1)!=0;
454 313 SnapshotFormat = zc_get_config(cfg_sect,"snapshot_format",3);
455 313 ShowBottomPixels = zc_get_config(cfg_sect,"bottom_8_px",0);
456 313 SnapshotScale = zc_get_config(cfg_sect,"snapshot_scale",2);
457 313 NameEntryMode = zc_get_config(cfg_sect,"name_entry_mode",0);
458 #ifdef __EMSCRIPTEN__
459 if (em_is_mobile()) NameEntryMode = 2;
460 #endif
461 313 ShowFPS = zc_get_config(cfg_sect,"showfps",0)!=0;
462 313 ShowGameTime = zc_get_config(cfg_sect,"showtime",0);
463 313 NESquit = zc_get_config(cfg_sect,"fastquit",0)!=0;
464 313 ClickToFreeze = zc_get_config(cfg_sect,"clicktofreeze",1)!=0;
465 313 abc_patternmatch = zc_get_config(cfg_sect, "lister_pattern_matching", 1);
466 313 pause_in_background = zc_get_config(cfg_sect, "pause_in_background", 0);
467
468 313 window_width = resx = zc_get_config(cfg_sect,"window_width",-1);
469 313 window_height = resy = zc_get_config(cfg_sect,"window_height",-1);
470 313 SaveDragResize = zc_get_config(cfg_sect,"save_drag_resize",0)!=0;
471 313 DragAspect = zc_get_config(cfg_sect,"drag_aspect",0)!=0;
472 313 SaveWinPos = zc_get_config(cfg_sect,"save_window_position",0)!=0;
473 313 scaleForceInteger = zc_get_config("zeldadx","scaling_force_integer",1)!=0;
474 313 stretchGame = zc_get_config("zeldadx","stretch_game_area",0)!=0;
475
476 313 loadlast = zc_get_config(cfg_sect,"load_last_path","");
477
478 313 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
479
480 313 info_opacity = zc_get_config("zc","debug_info_opacity",255);
481 #ifdef _WIN32
482 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
483 //use_win7_keyboard_fix = (byte) zc_get_config(cfg_sect,"use_win7_key_fix",0);
484 use_win32_proc = (byte) zc_get_config(cfg_sect,"zc_win_proc_fix",0); //buggy
485
486 // This one's for Aero
487 use_dwm_flush = (byte) zc_get_config("zeldadx","use_dwm_flush",0);
488
489 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
490 #else //UNIX
491 313 console_enabled = (byte) zc_get_config("CONSOLE", "enabled", 0);
492 313 monochrome_console = (byte) zc_get_config("CONSOLE","monochrome_debuggers",0);
493 #endif
494 313 clearConsoleOnLoad = zc_get_config("CONSOLE","clear_console_on_load",1)!=0;
495 313 clearConsoleOnReload = zc_get_config("CONSOLE","clear_console_on_reload",0)!=0;
496
497 313 strcpy(qstdir,zc_get_config(cfg_sect,"quest_dir","quests"));
498 313 strcpy(qstpath,qstdir); //qstpath is the local (for this run of ZC) quest path, qstdir is the universal quest dir.
499 313 ss_enable = zc_get_config(cfg_sect,"ss_enable",1) ? 1 : 0;
500 313 ss_after = vbound(zc_get_config(cfg_sect,"ss_after",14), 0, 14);
501 313 ss_speed = vbound(zc_get_config(cfg_sect,"ss_speed",2), 0, 6);
502 313 ss_density = vbound(zc_get_config(cfg_sect,"ss_density",3), 0, 6);
503 313 heart_beep = zc_get_config(cfg_sect,"heart_beep",0)!=0;
504 //gui_colorset = zc_get_config(cfg_sect,"gui_colorset",0);
505 313 sfxdat = zc_get_config(cfg_sect,"use_sfx_dat",1); // TODO: sfxdat is always set to 1 for titlescreen... and 0 in readsfx... so this cfg is pointless, remove?
506 313 fullscreen = zc_get_config(cfg_sect,"fullscreen",0);
507 313 use_save_indicator = zc_get_config(cfg_sect,"save_indicator",0);
508 313 zc_192b163_warp_compatibility = zc_get_config(cfg_sect,"zc_192b163_warp_compatibility",0);
509 313 SkipTitle = zc_get_config(cfg_sect,"skip_title",0);
510 313 }
511
512 void save_control_configs(bool kb)
513 {
514 if(kb)
515 {
516 zc_set_config(ctrl_sect,"key_cheatmod_a1",cheat_modifier_keys[0]);
517 zc_set_config(ctrl_sect,"key_cheatmod_a2",cheat_modifier_keys[1]);
518 zc_set_config(ctrl_sect,"key_cheatmod_b1",cheat_modifier_keys[2]);
519 zc_set_config(ctrl_sect,"key_cheatmod_b2",cheat_modifier_keys[3]);
520
521 if (!replay_is_replaying())
522 {
523 zc_set_config(ctrl_sect,"key_a",Akey);
524 zc_set_config(ctrl_sect,"key_b",Bkey);
525 zc_set_config(ctrl_sect,"key_s",Skey);
526 zc_set_config(ctrl_sect,"key_l",Lkey);
527 zc_set_config(ctrl_sect,"key_r",Rkey);
528 zc_set_config(ctrl_sect,"key_p",Pkey);
529 zc_set_config(ctrl_sect,"key_ex1",Exkey1);
530 zc_set_config(ctrl_sect,"key_ex2",Exkey2);
531 zc_set_config(ctrl_sect,"key_ex3",Exkey3);
532 zc_set_config(ctrl_sect,"key_ex4",Exkey4);
533 zc_set_config(ctrl_sect,"key_up", DUkey);
534 zc_set_config(ctrl_sect,"key_down", DDkey);
535 zc_set_config(ctrl_sect,"key_left", DLkey);
536 zc_set_config(ctrl_sect,"key_right",DRkey);
537 }
538 }
539 else
540 {
541 zc_set_config(ctrl_sect,"joystick_index",joystick_index);
542 zc_set_config(ctrl_sect,"js_stick_1_x_stick",js_stick_1_x_stick);
543 zc_set_config(ctrl_sect,"js_stick_1_x_axis",js_stick_1_x_axis);
544 zc_set_config(ctrl_sect,"js_stick_1_x_offset",js_stick_1_x_offset ? 1 : 0);
545 zc_set_config(ctrl_sect,"js_stick_1_y_stick",js_stick_1_y_stick);
546 zc_set_config(ctrl_sect,"js_stick_1_y_axis",js_stick_1_y_axis);
547 zc_set_config(ctrl_sect,"js_stick_1_y_offset",js_stick_1_y_offset ? 1 : 0);
548 zc_set_config(ctrl_sect,"js_stick_2_x_stick",js_stick_2_x_stick);
549 zc_set_config(ctrl_sect,"js_stick_2_x_axis",js_stick_2_x_axis);
550 zc_set_config(ctrl_sect,"js_stick_2_x_offset",js_stick_2_x_offset ? 1 : 0);
551 zc_set_config(ctrl_sect,"js_stick_2_y_stick",js_stick_2_y_stick);
552 zc_set_config(ctrl_sect,"js_stick_2_y_axis",js_stick_2_y_axis);
553 zc_set_config(ctrl_sect,"js_stick_2_y_offset",js_stick_2_y_offset ? 1 : 0);
554 zc_set_config(ctrl_sect,"analog_movement",analog_movement);
555
556 zc_set_config(ctrl_sect,"btn_a",Abtn);
557 zc_set_config(ctrl_sect,"btn_b",Bbtn);
558 zc_set_config(ctrl_sect,"btn_s",Sbtn);
559 zc_set_config(ctrl_sect,"btn_m",Mbtn);
560 zc_set_config(ctrl_sect,"btn_l",Lbtn);
561 zc_set_config(ctrl_sect,"btn_r",Rbtn);
562 zc_set_config(ctrl_sect,"btn_p",Pbtn);
563 zc_set_config(ctrl_sect,"btn_ex1",Exbtn1);
564 zc_set_config(ctrl_sect,"btn_ex2",Exbtn2);
565 zc_set_config(ctrl_sect,"btn_ex3",Exbtn3);
566 zc_set_config(ctrl_sect,"btn_ex4",Exbtn4);
567
568 zc_set_config(ctrl_sect,"btn_up",DUbtn);
569 zc_set_config(ctrl_sect,"btn_down",DDbtn);
570 zc_set_config(ctrl_sect,"btn_left",DLbtn);
571 zc_set_config(ctrl_sect,"btn_right",DRbtn);
572 }
573 }
574
575 void save_cheatkeys()
576 {
577 char buf[256];
578 for(size_t q = 1; q < Cheat::Last; ++q)
579 {
580 if(!bindable_cheat((Cheat)q)) continue;
581 std::string cheatname = cheat_to_string((Cheat)q);
582 util::lowerstr(cheatname);
583 sprintf(buf, "key_cheat_%s_main", cheatname.c_str());
584 zc_set_config(ctrl_sect,buf,cheatkeys[q][0]);
585 sprintf(buf, "key_cheat_%s_alt", cheatname.c_str());
586 if(cheatkeys[q][1])
587 zc_set_config(ctrl_sect,buf,cheatkeys[q][1]);
588 else zc_set_config(ctrl_sect,buf,(char*)nullptr);
589 }
590 }
591
592 313 void save_game_configs()
593 {
594
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
313 if (!loaded_game_configs) return;
595
596 313 packfile_password("");
597
598
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
313 if (all_get_display() && !all_get_fullscreen_flag()&& SaveWinPos)
599 {
600 int o_window_x, o_window_y;
601 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
602 zc_set_config(cfg_sect,"window_x",o_window_x);
603 zc_set_config(cfg_sect,"window_y",o_window_y);
604 }
605
606
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
313 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
607 {
608 window_width = al_get_display_width(all_get_display());
609 window_height = al_get_display_height(all_get_display());
610 zc_set_config(cfg_sect,"window_width",window_width);
611 zc_set_config(cfg_sect,"window_height",window_height);
612 }
613
614 313 zc_set_config(cfg_sect,"load_last_path",loadlast.c_str());
615 313 zc_set_config(cfg_sect,"use_sfx_dat",sfxdat);
616
617 313 flush_config_file();
618 #ifdef __EMSCRIPTEN__
619 em_sync_fs();
620 #endif
621 313 }
622
623 //----------------------------------------------------------------
624
625 // Timers
626
627 52833 void fps_callback()
628 {
629 52833 lastfps=framecnt;
630 52833 framecnt=0;
631 52833 }
632
633 END_OF_FUNCTION(fps_callback)
634
635 313 int32_t Z_init_timers()
636 {
637 static bool didit = false;
638 const static char *err_str = "Couldn't allocate timer";
639 313 err_str = err_str; //Unused variable warning
640
641
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
313 if(didit)
642 return 1;
643
644 313 didit = true;
645
646 LOCK_VARIABLE(lastfps);
647 LOCK_VARIABLE(framecnt);
648 LOCK_FUNCTION(fps_callback);
649
650
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
651 return 0;
652
653 313 return 1;
654 313 }
655
656 313 void Z_remove_timers()
657 {
658 313 remove_int(fps_callback);
659 313 }
660
661 //----------------------------------------------------------------
662
663 void go()
664 {
665 blit(screen,tmp_scr,scrx,scry,0,0,screen->w,screen->h);
666 }
667
668 void comeback()
669 {
670 blit(tmp_scr,screen,0,0,scrx,scry,screen->w,screen->h);
671 }
672
673 void dump_pal(BITMAP *dest)
674 {
675 for(int32_t i=0; i<256; i++)
676 rectfill(dest,(i&63)<<2,(i&0xFC0)>>4,((i&63)<<2)+3,((i&0xFC0)>>4)+3,i);
677 }
678
679 //----------------------------------------------------------------
680
681 int game_mouse_index = ZCM_BLANK;
682 static bool system_mouse = false;
683 92 bool sys_mouse()
684 {
685 92 system_mouse = true;
686 92 return MouseSprite::set(ZCM_NORMAL);
687 }
688 1626 bool game_mouse()
689 {
690 1626 system_mouse = false;
691 1626 return MouseSprite::set(game_mouse_index);
692 }
693 void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
694 {
695 if(!bmp)
696 return;
697 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
698 int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
699 if(bmp->w == scaledw && bmp->h == scaledh)
700 user_scale = false;
701 if(user_scale || sys_recolor)
702 {
703 if(!user_scale) scale = 1;
704 BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
705 if(user_scale)
706 stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
707 else
708 blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
709 if(sys_recolor)
710 recolor_mouse(tmpbmp);
711 MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
712 destroy_bitmap(tmpbmp);
713 }
714 else
715 {
716 MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
717 }
718 }
719
720 //Handles converting the mouse sprite from the .dat file
721 void recolor_mouse(BITMAP* bmp)
722 {
723 for(int32_t x = 0; x < bmp->w; ++x)
724 {
725 for(int32_t y = 0; y < bmp->h; ++y)
726 {
727 int32_t color = getpixel(bmp, x, y);
728 switch(color)
729 {
730 case dvc(1):
731 color = jwin_pal[jcCURSORMISC];
732 break;
733 case dvc(2):
734 color = jwin_pal[jcCURSOROUTLINE];
735 break;
736 case dvc(3):
737 color = jwin_pal[jcCURSORLIGHT];
738 break;
739 case dvc(5):
740 color = jwin_pal[jcCURSORDARK];
741 break;
742 default:
743 continue;
744 }
745 putpixel(bmp, x, y, color);
746 }
747 }
748 }
749 void load_mouse()
750 {
751 PALETTE pal;
752 BITMAP* cursor_bitmap = load_bitmap("assets/cursor.bmp", pal);
753 if (!cursor_bitmap)
754 Z_error_fatal("Missing required file %s\n", "assets/cursor.bmp");
755
756 enter_sys_pal();
757 MouseSprite::set(-1);
758 float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
759 int32_t sz = 16*scale;
760 for(int32_t j = 0; j < 1; ++j)
761 {
762 BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
763 if(zcmouse[j])
764 destroy_bitmap(zcmouse[j]);
765 zcmouse[j] = create_bitmap_ex(8,sz,sz);
766 clear_bitmap(zcmouse[j]);
767 clear_bitmap(tmpbmp);
768 blit(cursor_bitmap,tmpbmp,1,j*17+1,0,0,16,16);
769 recolor_mouse(tmpbmp);
770 if(sz!=16)
771 stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
772 else
773 blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
774 destroy_bitmap(tmpbmp);
775 }
776 if(!hw_palette) hw_palette = &RAMpal;
777 zc_set_palette(*hw_palette);
778
779 BITMAP* blankmouse = create_bitmap_ex(8,16,16);
780 clear_bitmap(blankmouse);
781
782 MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
783 MouseSprite::assign(ZCM_BLANK, blankmouse);
784 //Don't assign ZCM_CUSTOM. That'll be handled by scripts.
785
786 //Reload the mouse
787 if(system_mouse)
788 sys_mouse();
789 else game_mouse();
790
791 destroy_bitmap(blankmouse);
792 destroy_bitmap(cursor_bitmap);
793 exit_sys_pal();
794 }
795
796 // sets the video mode and initializes the palette and mouse sprite
797 313 bool game_vid_mode(int32_t mode,int32_t wait)
798 {
799
1/2
✓ Branch 0 taken 313 times.
✗ Branch 1 not taken.
313 if (is_headless())
800 313 return true;
801
802 extern int zq_screen_w, zq_screen_h;
803 if(set_gfx_mode(mode,resx,resy,zq_screen_w,zq_screen_h)!=0)
804 {
805 return false;
806 }
807
808 scrx = (resx-320)>>1;
809 scry = (resy-240)>>1;
810 for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
811 zcmouse[q] = NULL;
812 load_mouse();
813
814 for(int32_t i=240; i<256; i++)
815 RAMpal[i]=pal_gui[i];
816
817 zc_set_palette(RAMpal);
818 clear_to_color(screen,BLACK);
819
820 rest(wait);
821 return true;
822 313 }
823
824 321 void null_quest()
825 {
826
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 std::string title_assets_path = "modules/classic/title_gfx.dat";
827
2/4
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 321 times.
321 if (get_last_loaded_qstpath() == title_assets_path)
828 return;
829
830 byte skip_flags[4];
831
2/2
✓ Branch 0 taken 321 times.
✓ Branch 1 taken 8346 times.
8667 for (int i = 0; i < skip_max; i++)
832
1/2
✓ Branch 0 taken 8346 times.
✗ Branch 1 not taken.
8346 set_bit(skip_flags, i, 1);
833
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 set_bit(skip_flags, skip_tiles, 0);
834
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 set_bit(skip_flags, skip_csets, 0);
835
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 set_bit(skip_flags, skip_misc, 0); // needed for miscsfx (skip this and `tests/replays/demons_inferno/demons_inferno_1_of_2.zplay` fails).
836
1/2
✓ Branch 0 taken 321 times.
✗ Branch 1 not taken.
321 loadquest(title_assets_path.c_str(), &QHeader, &QMisc, tunes+ZC_MIDI_COUNT, false, skip_flags, 0, false);
837 321 sfxdat = 1;
838 // TODO: sfx.dat is ~1.2 MB. Could be better to break that up into individual files and load on demand / not at startup.
839 // TODO: can we cache the tiles/colordata so we don't have to read title_gfx.dat more than once?
840 // colordata is tiny, but tilebuf is huge, so limit that to just what the title screen needs.
841 // Another option: embed this data into the binary (`xxd -i resources/modules/classic/title_gfx.dat > title_gfx.h`)
842
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 321 times.
321 }
843
844 321 void init_NES_mode()
845 {
846 321 null_quest();
847 321 }
848
849 //----------------------------------------------------------------
850
851 qword trianglelines[16]=
852 {
853 0x0000000000000000ULL,
854 0xFD00000000000000ULL,
855 0xFDFD000000000000ULL,
856 0xFDFDFD0000000000ULL,
857 0xFDFDFDFD00000000ULL,
858 0xFDFDFDFDFD000000ULL,
859 0xFDFDFDFDFDFD0000ULL,
860 0xFDFDFDFDFDFDFD00ULL,
861 0xFDFDFDFDFDFDFDFDULL,
862 0x00FDFDFDFDFDFDFDULL,
863 0x0000FDFDFDFDFDFDULL,
864 0x000000FDFDFDFDFDULL,
865 0x00000000FDFDFDFDULL,
866 0x0000000000FDFDFDULL,
867 0x000000000000FDFDULL,
868 0x00000000000000FDULL,
869 };
870
871 word screen_triangles[29][32];
872
873 // the ULL suffixes are to prevent this warning:
874 // warning: integer constant is too large for "int32_t" type
875
876 qword triangles[4][16][8]= //[direction][value][line]
877 {
878 {
879 {
880 0x0000000000000000ULL,
881 0x0000000000000000ULL,
882 0x0000000000000000ULL,
883 0x0000000000000000ULL,
884 0x0000000000000000ULL,
885 0x0000000000000000ULL,
886 0x0000000000000000ULL,
887 0x0000000000000000ULL
888 },
889 {
890 0xFD00000000000000ULL,
891 0x0000000000000000ULL,
892 0x0000000000000000ULL,
893 0x0000000000000000ULL,
894 0x0000000000000000ULL,
895 0x0000000000000000ULL,
896 0x0000000000000000ULL,
897 0x0000000000000000ULL
898 },
899 {
900 0xFDFD000000000000ULL,
901 0xFD00000000000000ULL,
902 0x0000000000000000ULL,
903 0x0000000000000000ULL,
904 0x0000000000000000ULL,
905 0x0000000000000000ULL,
906 0x0000000000000000ULL,
907 0x0000000000000000ULL
908 },
909 {
910 0xFDFDFD0000000000ULL,
911 0xFDFD000000000000ULL,
912 0xFD00000000000000ULL,
913 0x0000000000000000ULL,
914 0x0000000000000000ULL,
915 0x0000000000000000ULL,
916 0x0000000000000000ULL,
917 0x0000000000000000ULL
918 },
919 {
920 0xFDFDFDFD00000000ULL,
921 0xFDFDFD0000000000ULL,
922 0xFDFD000000000000ULL,
923 0xFD00000000000000ULL,
924 0x0000000000000000ULL,
925 0x0000000000000000ULL,
926 0x0000000000000000ULL,
927 0x0000000000000000ULL
928 },
929 {
930 0xFDFDFDFDFD000000ULL,
931 0xFDFDFDFD00000000ULL,
932 0xFDFDFD0000000000ULL,
933 0xFDFD000000000000ULL,
934 0xFD00000000000000ULL,
935 0x0000000000000000ULL,
936 0x0000000000000000ULL,
937 0x0000000000000000ULL
938 },
939 {
940 0xFDFDFDFDFDFD0000ULL,
941 0xFDFDFDFDFD000000ULL,
942 0xFDFDFDFD00000000ULL,
943 0xFDFDFD0000000000ULL,
944 0xFDFD000000000000ULL,
945 0xFD00000000000000ULL,
946 0x0000000000000000ULL,
947 0x0000000000000000ULL
948 },
949 {
950 0xFDFDFDFDFDFDFD00ULL,
951 0xFDFDFDFDFDFD0000ULL,
952 0xFDFDFDFDFD000000ULL,
953 0xFDFDFDFD00000000ULL,
954 0xFDFDFD0000000000ULL,
955 0xFDFD000000000000ULL,
956 0xFD00000000000000ULL,
957 0x0000000000000000ULL
958 },
959 {
960 0xFDFDFDFDFDFDFDFDULL,
961 0xFDFDFDFDFDFDFD00ULL,
962 0xFDFDFDFDFDFD0000ULL,
963 0xFDFDFDFDFD000000ULL,
964 0xFDFDFDFD00000000ULL,
965 0xFDFDFD0000000000ULL,
966 0xFDFD000000000000ULL,
967 0xFD00000000000000ULL
968 },
969 {
970 0xFDFDFDFDFDFDFDFDULL,
971 0xFDFDFDFDFDFDFDFDULL,
972 0xFDFDFDFDFDFDFD00ULL,
973 0xFDFDFDFDFDFD0000ULL,
974 0xFDFDFDFDFD000000ULL,
975 0xFDFDFDFD00000000ULL,
976 0xFDFDFD0000000000ULL,
977 0xFDFD000000000000ULL
978 },
979 {
980 0xFDFDFDFDFDFDFDFDULL,
981 0xFDFDFDFDFDFDFDFDULL,
982 0xFDFDFDFDFDFDFDFDULL,
983 0xFDFDFDFDFDFDFD00ULL,
984 0xFDFDFDFDFDFD0000ULL,
985 0xFDFDFDFDFD000000ULL,
986 0xFDFDFDFD00000000ULL,
987 0xFDFDFD0000000000ULL
988 },
989 {
990 0xFDFDFDFDFDFDFDFDULL,
991 0xFDFDFDFDFDFDFDFDULL,
992 0xFDFDFDFDFDFDFDFDULL,
993 0xFDFDFDFDFDFDFDFDULL,
994 0xFDFDFDFDFDFDFD00ULL,
995 0xFDFDFDFDFDFD0000ULL,
996 0xFDFDFDFDFD000000ULL,
997 0xFDFDFDFD00000000ULL
998 },
999 {
1000 0xFDFDFDFDFDFDFDFDULL,
1001 0xFDFDFDFDFDFDFDFDULL,
1002 0xFDFDFDFDFDFDFDFDULL,
1003 0xFDFDFDFDFDFDFDFDULL,
1004 0xFDFDFDFDFDFDFDFDULL,
1005 0xFDFDFDFDFDFDFD00ULL,
1006 0xFDFDFDFDFDFD0000ULL,
1007 0xFDFDFDFDFD000000ULL
1008 },
1009 {
1010 0xFDFDFDFDFDFDFDFDULL,
1011 0xFDFDFDFDFDFDFDFDULL,
1012 0xFDFDFDFDFDFDFDFDULL,
1013 0xFDFDFDFDFDFDFDFDULL,
1014 0xFDFDFDFDFDFDFDFDULL,
1015 0xFDFDFDFDFDFDFDFDULL,
1016 0xFDFDFDFDFDFDFD00ULL,
1017 0xFDFDFDFDFDFD0000ULL
1018 },
1019 {
1020 0xFDFDFDFDFDFDFDFDULL,
1021 0xFDFDFDFDFDFDFDFDULL,
1022 0xFDFDFDFDFDFDFDFDULL,
1023 0xFDFDFDFDFDFDFDFDULL,
1024 0xFDFDFDFDFDFDFDFDULL,
1025 0xFDFDFDFDFDFDFDFDULL,
1026 0xFDFDFDFDFDFDFDFDULL,
1027 0xFDFDFDFDFDFDFD00ULL
1028 },
1029 {
1030 0xFDFDFDFDFDFDFDFDULL,
1031 0xFDFDFDFDFDFDFDFDULL,
1032 0xFDFDFDFDFDFDFDFDULL,
1033 0xFDFDFDFDFDFDFDFDULL,
1034 0xFDFDFDFDFDFDFDFDULL,
1035 0xFDFDFDFDFDFDFDFDULL,
1036 0xFDFDFDFDFDFDFDFDULL,
1037 0xFDFDFDFDFDFDFDFDULL
1038 }
1039 },
1040 {
1041 {
1042 0x0000000000000000ULL,
1043 0x0000000000000000ULL,
1044 0x0000000000000000ULL,
1045 0x0000000000000000ULL,
1046 0x0000000000000000ULL,
1047 0x0000000000000000ULL,
1048 0x0000000000000000ULL,
1049 0x0000000000000000ULL
1050 },
1051 {
1052 0x00000000000000FDULL,
1053 0x0000000000000000ULL,
1054 0x0000000000000000ULL,
1055 0x0000000000000000ULL,
1056 0x0000000000000000ULL,
1057 0x0000000000000000ULL,
1058 0x0000000000000000ULL,
1059 0x0000000000000000ULL
1060 },
1061 {
1062 0x000000000000FDFDULL,
1063 0x00000000000000FDULL,
1064 0x0000000000000000ULL,
1065 0x0000000000000000ULL,
1066 0x0000000000000000ULL,
1067 0x0000000000000000ULL,
1068 0x0000000000000000ULL,
1069 0x0000000000000000ULL
1070 },
1071 {
1072 0x0000000000FDFDFDULL,
1073 0x000000000000FDFDULL,
1074 0x00000000000000FDULL,
1075 0x0000000000000000ULL,
1076 0x0000000000000000ULL,
1077 0x0000000000000000ULL,
1078 0x0000000000000000ULL,
1079 0x0000000000000000ULL
1080 },
1081 {
1082 0x00000000FDFDFDFDULL,
1083 0x0000000000FDFDFDULL,
1084 0x000000000000FDFDULL,
1085 0x00000000000000FDULL,
1086 0x0000000000000000ULL,
1087 0x0000000000000000ULL,
1088 0x0000000000000000ULL,
1089 0x0000000000000000ULL
1090 },
1091 {
1092 0x000000FDFDFDFDFDULL,
1093 0x00000000FDFDFDFDULL,
1094 0x0000000000FDFDFDULL,
1095 0x000000000000FDFDULL,
1096 0x00000000000000FDULL,
1097 0x0000000000000000ULL,
1098 0x0000000000000000ULL,
1099 0x0000000000000000ULL
1100 },
1101 {
1102 0x0000FDFDFDFDFDFDULL,
1103 0x000000FDFDFDFDFDULL,
1104 0x00000000FDFDFDFDULL,
1105 0x0000000000FDFDFDULL,
1106 0x000000000000FDFDULL,
1107 0x00000000000000FDULL,
1108 0x0000000000000000ULL,
1109 0x0000000000000000ULL
1110 },
1111 {
1112 0x00FDFDFDFDFDFDFDULL,
1113 0x0000FDFDFDFDFDFDULL,
1114 0x000000FDFDFDFDFDULL,
1115 0x00000000FDFDFDFDULL,
1116 0x0000000000FDFDFDULL,
1117 0x000000000000FDFDULL,
1118 0x00000000000000FDULL,
1119 0x0000000000000000ULL
1120 },
1121 {
1122 0xFDFDFDFDFDFDFDFDULL,
1123 0x00FDFDFDFDFDFDFDULL,
1124 0x0000FDFDFDFDFDFDULL,
1125 0x000000FDFDFDFDFDULL,
1126 0x00000000FDFDFDFDULL,
1127 0x0000000000FDFDFDULL,
1128 0x000000000000FDFDULL,
1129 0x00000000000000FDULL
1130 },
1131 {
1132 0xFDFDFDFDFDFDFDFDULL,
1133 0xFDFDFDFDFDFDFDFDULL,
1134 0x00FDFDFDFDFDFDFDULL,
1135 0x0000FDFDFDFDFDFDULL,
1136 0x000000FDFDFDFDFDULL,
1137 0x00000000FDFDFDFDULL,
1138 0x0000000000FDFDFDULL,
1139 0x000000000000FDFDULL
1140 },
1141 {
1142 0xFDFDFDFDFDFDFDFDULL,
1143 0xFDFDFDFDFDFDFDFDULL,
1144 0xFDFDFDFDFDFDFDFDULL,
1145 0x00FDFDFDFDFDFDFDULL,
1146 0x0000FDFDFDFDFDFDULL,
1147 0x000000FDFDFDFDFDULL,
1148 0x00000000FDFDFDFDULL,
1149 0x0000000000FDFDFDULL
1150 },
1151 {
1152 0xFDFDFDFDFDFDFDFDULL,
1153 0xFDFDFDFDFDFDFDFDULL,
1154 0xFDFDFDFDFDFDFDFDULL,
1155 0xFDFDFDFDFDFDFDFDULL,
1156 0x00FDFDFDFDFDFDFDULL,
1157 0x0000FDFDFDFDFDFDULL,
1158 0x000000FDFDFDFDFDULL,
1159 0x00000000FDFDFDFDULL
1160 },
1161 {
1162 0xFDFDFDFDFDFDFDFDULL,
1163 0xFDFDFDFDFDFDFDFDULL,
1164 0xFDFDFDFDFDFDFDFDULL,
1165 0xFDFDFDFDFDFDFDFDULL,
1166 0xFDFDFDFDFDFDFDFDULL,
1167 0x00FDFDFDFDFDFDFDULL,
1168 0x0000FDFDFDFDFDFDULL,
1169 0x000000FDFDFDFDFDULL
1170 },
1171 {
1172 0xFDFDFDFDFDFDFDFDULL,
1173 0xFDFDFDFDFDFDFDFDULL,
1174 0xFDFDFDFDFDFDFDFDULL,
1175 0xFDFDFDFDFDFDFDFDULL,
1176 0xFDFDFDFDFDFDFDFDULL,
1177 0xFDFDFDFDFDFDFDFDULL,
1178 0x00FDFDFDFDFDFDFDULL,
1179 0x0000FDFDFDFDFDFDULL
1180 },
1181 {
1182 0xFDFDFDFDFDFDFDFDULL,
1183 0xFDFDFDFDFDFDFDFDULL,
1184 0xFDFDFDFDFDFDFDFDULL,
1185 0xFDFDFDFDFDFDFDFDULL,
1186 0xFDFDFDFDFDFDFDFDULL,
1187 0xFDFDFDFDFDFDFDFDULL,
1188 0xFDFDFDFDFDFDFDFDULL,
1189 0x00FDFDFDFDFDFDFDULL
1190 },
1191 {
1192 0xFDFDFDFDFDFDFDFDULL,
1193 0xFDFDFDFDFDFDFDFDULL,
1194 0xFDFDFDFDFDFDFDFDULL,
1195 0xFDFDFDFDFDFDFDFDULL,
1196 0xFDFDFDFDFDFDFDFDULL,
1197 0xFDFDFDFDFDFDFDFDULL,
1198 0xFDFDFDFDFDFDFDFDULL,
1199 0xFDFDFDFDFDFDFDFDULL
1200 }
1201 },
1202 {
1203 {
1204 0x0000000000000000ULL,
1205 0x0000000000000000ULL,
1206 0x0000000000000000ULL,
1207 0x0000000000000000ULL,
1208 0x0000000000000000ULL,
1209 0x0000000000000000ULL,
1210 0x0000000000000000ULL,
1211 0x0000000000000000ULL
1212 },
1213 {
1214 0x0000000000000000ULL,
1215 0x0000000000000000ULL,
1216 0x0000000000000000ULL,
1217 0x0000000000000000ULL,
1218 0x0000000000000000ULL,
1219 0x0000000000000000ULL,
1220 0x0000000000000000ULL,
1221 0xFD00000000000000ULL
1222 },
1223 {
1224 0x0000000000000000ULL,
1225 0x0000000000000000ULL,
1226 0x0000000000000000ULL,
1227 0x0000000000000000ULL,
1228 0x0000000000000000ULL,
1229 0x0000000000000000ULL,
1230 0xFD00000000000000ULL,
1231 0xFDFD000000000000ULL
1232 },
1233 {
1234 0x0000000000000000ULL,
1235 0x0000000000000000ULL,
1236 0x0000000000000000ULL,
1237 0x0000000000000000ULL,
1238 0x0000000000000000ULL,
1239 0xFD00000000000000ULL,
1240 0xFDFD000000000000ULL,
1241 0xFDFDFD0000000000ULL
1242 },
1243 {
1244 0x0000000000000000ULL,
1245 0x0000000000000000ULL,
1246 0x0000000000000000ULL,
1247 0x0000000000000000ULL,
1248 0xFD00000000000000ULL,
1249 0xFDFD000000000000ULL,
1250 0xFDFDFD0000000000ULL,
1251 0xFDFDFDFD00000000ULL
1252 },
1253 {
1254 0x0000000000000000ULL,
1255 0x0000000000000000ULL,
1256 0x0000000000000000ULL,
1257 0xFD00000000000000ULL,
1258 0xFDFD000000000000ULL,
1259 0xFDFDFD0000000000ULL,
1260 0xFDFDFDFD00000000ULL,
1261 0xFDFDFDFDFD000000ULL
1262 },
1263 {
1264 0x0000000000000000ULL,
1265 0x0000000000000000ULL,
1266 0xFD00000000000000ULL,
1267 0xFDFD000000000000ULL,
1268 0xFDFDFD0000000000ULL,
1269 0xFDFDFDFD00000000ULL,
1270 0xFDFDFDFDFD000000ULL,
1271 0xFDFDFDFDFDFD0000ULL
1272 },
1273 {
1274 0x0000000000000000ULL,
1275 0xFD00000000000000ULL,
1276 0xFDFD000000000000ULL,
1277 0xFDFDFD0000000000ULL,
1278 0xFDFDFDFD00000000ULL,
1279 0xFDFDFDFDFD000000ULL,
1280 0xFDFDFDFDFDFD0000ULL,
1281 0xFDFDFDFDFDFDFD00ULL
1282 },
1283 {
1284 0xFD00000000000000ULL,
1285 0xFDFD000000000000ULL,
1286 0xFDFDFD0000000000ULL,
1287 0xFDFDFDFD00000000ULL,
1288 0xFDFDFDFDFD000000ULL,
1289 0xFDFDFDFDFDFD0000ULL,
1290 0xFDFDFDFDFDFDFD00ULL,
1291 0xFDFDFDFDFDFDFDFDULL
1292 },
1293 {
1294 0xFDFD000000000000ULL,
1295 0xFDFDFD0000000000ULL,
1296 0xFDFDFDFD00000000ULL,
1297 0xFDFDFDFDFD000000ULL,
1298 0xFDFDFDFDFDFD0000ULL,
1299 0xFDFDFDFDFDFDFD00ULL,
1300 0xFDFDFDFDFDFDFDFDULL,
1301 0xFDFDFDFDFDFDFDFDULL
1302 },
1303 {
1304 0xFDFDFD0000000000ULL,
1305 0xFDFDFDFD00000000ULL,
1306 0xFDFDFDFDFD000000ULL,
1307 0xFDFDFDFDFDFD0000ULL,
1308 0xFDFDFDFDFDFDFD00ULL,
1309 0xFDFDFDFDFDFDFDFDULL,
1310 0xFDFDFDFDFDFDFDFDULL,
1311 0xFDFDFDFDFDFDFDFDULL
1312 },
1313 {
1314 0xFDFDFDFD00000000ULL,
1315 0xFDFDFDFDFD000000ULL,
1316 0xFDFDFDFDFDFD0000ULL,
1317 0xFDFDFDFDFDFDFD00ULL,
1318 0xFDFDFDFDFDFDFDFDULL,
1319 0xFDFDFDFDFDFDFDFDULL,
1320 0xFDFDFDFDFDFDFDFDULL,
1321 0xFDFDFDFDFDFDFDFDULL
1322 },
1323 {
1324 0xFDFDFDFDFD000000ULL,
1325 0xFDFDFDFDFDFD0000ULL,
1326 0xFDFDFDFDFDFDFD00ULL,
1327 0xFDFDFDFDFDFDFDFDULL,
1328 0xFDFDFDFDFDFDFDFDULL,
1329 0xFDFDFDFDFDFDFDFDULL,
1330 0xFDFDFDFDFDFDFDFDULL,
1331 0xFDFDFDFDFDFDFDFDULL
1332 },
1333 {
1334 0xFDFDFDFDFDFD0000ULL,
1335 0xFDFDFDFDFDFDFD00ULL,
1336 0xFDFDFDFDFDFDFDFDULL,
1337 0xFDFDFDFDFDFDFDFDULL,
1338 0xFDFDFDFDFDFDFDFDULL,
1339 0xFDFDFDFDFDFDFDFDULL,
1340 0xFDFDFDFDFDFDFDFDULL,
1341 0xFDFDFDFDFDFDFDFDULL
1342 },
1343 {
1344 0xFDFDFDFDFDFDFD00ULL,
1345 0xFDFDFDFDFDFDFDFDULL,
1346 0xFDFDFDFDFDFDFDFDULL,
1347 0xFDFDFDFDFDFDFDFDULL,
1348 0xFDFDFDFDFDFDFDFDULL,
1349 0xFDFDFDFDFDFDFDFDULL,
1350 0xFDFDFDFDFDFDFDFDULL,
1351 0xFDFDFDFDFDFDFDFDULL
1352 },
1353 {
1354 0xFDFDFDFDFDFDFDFDULL,
1355 0xFDFDFDFDFDFDFDFDULL,
1356 0xFDFDFDFDFDFDFDFDULL,
1357 0xFDFDFDFDFDFDFDFDULL,
1358 0xFDFDFDFDFDFDFDFDULL,
1359 0xFDFDFDFDFDFDFDFDULL,
1360 0xFDFDFDFDFDFDFDFDULL,
1361 0xFDFDFDFDFDFDFDFDULL
1362 }
1363 },
1364 {
1365 {
1366 0x0000000000000000ULL,
1367 0x0000000000000000ULL,
1368 0x0000000000000000ULL,
1369 0x0000000000000000ULL,
1370 0x0000000000000000ULL,
1371 0x0000000000000000ULL,
1372 0x0000000000000000ULL,
1373 0x0000000000000000ULL
1374 },
1375 {
1376 0x0000000000000000ULL,
1377 0x0000000000000000ULL,
1378 0x0000000000000000ULL,
1379 0x0000000000000000ULL,
1380 0x0000000000000000ULL,
1381 0x0000000000000000ULL,
1382 0x0000000000000000ULL,
1383 0x00000000000000FDULL
1384 },
1385 {
1386 0x0000000000000000ULL,
1387 0x0000000000000000ULL,
1388 0x0000000000000000ULL,
1389 0x0000000000000000ULL,
1390 0x0000000000000000ULL,
1391 0x0000000000000000ULL,
1392 0x00000000000000FDULL,
1393 0x000000000000FDFDULL
1394 },
1395 {
1396 0x0000000000000000ULL,
1397 0x0000000000000000ULL,
1398 0x0000000000000000ULL,
1399 0x0000000000000000ULL,
1400 0x0000000000000000ULL,
1401 0x00000000000000FDULL,
1402 0x000000000000FDFDULL,
1403 0x0000000000FDFDFDULL
1404 },
1405 {
1406 0x0000000000000000ULL,
1407 0x0000000000000000ULL,
1408 0x0000000000000000ULL,
1409 0x0000000000000000ULL,
1410 0x00000000000000FDULL,
1411 0x000000000000FDFDULL,
1412 0x0000000000FDFDFDULL,
1413 0x00000000FDFDFDFDULL
1414 },
1415 {
1416 0x0000000000000000ULL,
1417 0x0000000000000000ULL,
1418 0x0000000000000000ULL,
1419 0x00000000000000FDULL,
1420 0x000000000000FDFDULL,
1421 0x0000000000FDFDFDULL,
1422 0x00000000FDFDFDFDULL,
1423 0x000000FDFDFDFDFDULL
1424 },
1425 {
1426 0x0000000000000000ULL,
1427 0x0000000000000000ULL,
1428 0x00000000000000FDULL,
1429 0x000000000000FDFDULL,
1430 0x0000000000FDFDFDULL,
1431 0x00000000FDFDFDFDULL,
1432 0x000000FDFDFDFDFDULL,
1433 0x0000FDFDFDFDFDFDULL
1434 },
1435 {
1436 0x0000000000000000ULL,
1437 0x00000000000000FDULL,
1438 0x000000000000FDFDULL,
1439 0x0000000000FDFDFDULL,
1440 0x00000000FDFDFDFDULL,
1441 0x000000FDFDFDFDFDULL,
1442 0x0000FDFDFDFDFDFDULL,
1443 0x00FDFDFDFDFDFDFDULL
1444 },
1445 {
1446 0x00000000000000FDULL,
1447 0x000000000000FDFDULL,
1448 0x0000000000FDFDFDULL,
1449 0x00000000FDFDFDFDULL,
1450 0x000000FDFDFDFDFDULL,
1451 0x0000FDFDFDFDFDFDULL,
1452 0x00FDFDFDFDFDFDFDULL,
1453 0xFDFDFDFDFDFDFDFDULL
1454 },
1455 {
1456 0x000000000000FDFDULL,
1457 0x0000000000FDFDFDULL,
1458 0x00000000FDFDFDFDULL,
1459 0x000000FDFDFDFDFDULL,
1460 0x0000FDFDFDFDFDFDULL,
1461 0x00FDFDFDFDFDFDFDULL,
1462 0xFDFDFDFDFDFDFDFDULL,
1463 0xFDFDFDFDFDFDFDFDULL
1464 },
1465 {
1466 0x0000000000FDFDFDULL,
1467 0x00000000FDFDFDFDULL,
1468 0x000000FDFDFDFDFDULL,
1469 0x0000FDFDFDFDFDFDULL,
1470 0x00FDFDFDFDFDFDFDULL,
1471 0xFDFDFDFDFDFDFDFDULL,
1472 0xFDFDFDFDFDFDFDFDULL,
1473 0xFDFDFDFDFDFDFDFDULL
1474 },
1475 {
1476 0x00000000FDFDFDFDULL,
1477 0x000000FDFDFDFDFDULL,
1478 0x0000FDFDFDFDFDFDULL,
1479 0x00FDFDFDFDFDFDFDULL,
1480 0xFDFDFDFDFDFDFDFDULL,
1481 0xFDFDFDFDFDFDFDFDULL,
1482 0xFDFDFDFDFDFDFDFDULL,
1483 0xFDFDFDFDFDFDFDFDULL
1484 },
1485 {
1486 0x000000FDFDFDFDFDULL,
1487 0x0000FDFDFDFDFDFDULL,
1488 0x00FDFDFDFDFDFDFDULL,
1489 0xFDFDFDFDFDFDFDFDULL,
1490 0xFDFDFDFDFDFDFDFDULL,
1491 0xFDFDFDFDFDFDFDFDULL,
1492 0xFDFDFDFDFDFDFDFDULL,
1493 0xFDFDFDFDFDFDFDFDULL
1494 },
1495 {
1496 0x0000FDFDFDFDFDFDULL,
1497 0x00FDFDFDFDFDFDFDULL,
1498 0xFDFDFDFDFDFDFDFDULL,
1499 0xFDFDFDFDFDFDFDFDULL,
1500 0xFDFDFDFDFDFDFDFDULL,
1501 0xFDFDFDFDFDFDFDFDULL,
1502 0xFDFDFDFDFDFDFDFDULL,
1503 0xFDFDFDFDFDFDFDFDULL
1504 },
1505 {
1506 0x00FDFDFDFDFDFDFDULL,
1507 0xFDFDFDFDFDFDFDFDULL,
1508 0xFDFDFDFDFDFDFDFDULL,
1509 0xFDFDFDFDFDFDFDFDULL,
1510 0xFDFDFDFDFDFDFDFDULL,
1511 0xFDFDFDFDFDFDFDFDULL,
1512 0xFDFDFDFDFDFDFDFDULL,
1513 0xFDFDFDFDFDFDFDFDULL
1514 },
1515 {
1516 0xFDFDFDFDFDFDFDFDULL,
1517 0xFDFDFDFDFDFDFDFDULL,
1518 0xFDFDFDFDFDFDFDFDULL,
1519 0xFDFDFDFDFDFDFDFDULL,
1520 0xFDFDFDFDFDFDFDFDULL,
1521 0xFDFDFDFDFDFDFDFDULL,
1522 0xFDFDFDFDFDFDFDFDULL,
1523 0xFDFDFDFDFDFDFDFDULL
1524 }
1525 }
1526 };
1527
1528 static bool is_opening_screen;
1529 int32_t black_opening_count=0;
1530 int32_t black_opening_x,black_opening_y;
1531 int32_t black_opening_shape;
1532
1533 3282 int32_t choose_opening_shape()
1534 {
1535 // First, count how many bits are set
1536 3282 int32_t numBits=0;
1537 int32_t bitCounter;
1538
1539
2/2
✓ Branch 0 taken 16410 times.
✓ Branch 1 taken 3282 times.
19692 for(int32_t i=0; i<bosMAX; i++)
1540 {
1541
2/2
✓ Branch 0 taken 12912 times.
✓ Branch 1 taken 3498 times.
16410 if(COOLSCROLL&(1<<i))
1542 3498 numBits++;
1543 16410 }
1544
1545 // Shouldn't happen...
1546
1/2
✓ Branch 0 taken 3282 times.
✗ Branch 1 not taken.
3282 if(numBits==0)
1547 return bosCIRCLE;
1548
1549 // Pick a bit
1550 3282 bitCounter=zc_rand()%numBits+1;
1551
1552
2/2
✓ Branch 0 taken 4476 times.
✓ Branch 1 taken 26 times.
4502 for(int32_t i=0; i<bosMAX; i++)
1553 {
1554 // If this bit is set, decrement the bit counter
1555
2/2
✓ Branch 0 taken 1064 times.
✓ Branch 1 taken 3412 times.
4476 if(COOLSCROLL&(1<<i))
1556 3412 bitCounter--;
1557
1558 // When the counter hits 0, return a value based on
1559 // which bit it stopped on.
1560 // Reminder: enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
1561
2/2
✓ Branch 0 taken 3256 times.
✓ Branch 1 taken 1220 times.
4476 if(bitCounter==0)
1562 3256 return i;
1563 1220 }
1564
1565 // Shouldn't be necessary, but the compiler might complain, at least
1566 26 return bosCIRCLE;
1567 3282 }
1568
1569 739 void close_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1570 {
1571 739 x -= viewport.x;
1572 739 y -= viewport.y;
1573
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 729 times.
739 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1574
1575 739 int32_t w=framebuf->w, h=framebuf->h;
1576 739 int32_t blockrows=h/8, blockcolumns=32;
1577 739 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1578
1579
2/2
✓ Branch 0 taken 20692 times.
✓ Branch 1 taken 739 times.
21431 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1580 {
1581
2/2
✓ Branch 0 taken 662144 times.
✓ Branch 1 taken 20692 times.
682836 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1582 {
1583
2/2
✓ Branch 0 taken 273677 times.
✓ Branch 1 taken 388467 times.
662144 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1584 662144 }
1585 20692 }
1586
1587 739 black_opening_count = 66;
1588 739 black_opening_x = x;
1589 739 black_opening_y = y;
1590 739 lensclk = 0;
1591 //black_opening_shape=(black_opening_shape+1)%bosMAX;
1592
1593
1594
1/2
✓ Branch 0 taken 739 times.
✗ Branch 1 not taken.
739 if(black_opening_shape == bosFADEBLACK)
1595 {
1596 refreshTints();
1597 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1598 }
1599
2/2
✓ Branch 0 taken 725 times.
✓ Branch 1 taken 14 times.
739 if(wait)
1600 {
1601 14 FFCore.warpScriptCheck();
1602
2/2
✓ Branch 0 taken 14 times.
✓ Branch 1 taken 924 times.
938 for(int32_t i=0; i<66; i++)
1603 {
1604 924 draw_screen();
1605 924 advanceframe(true);
1606
1607
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 924 times.
924 if(Quit)
1608 {
1609 break;
1610 }
1611 924 }
1612 14 }
1613 739 }
1614
1615 2563 void open_black_opening(int32_t x, int32_t y, bool wait, int32_t shape)
1616 {
1617 2563 x -= viewport.x;
1618 2563 y -= viewport.y;
1619
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 2553 times.
2563 black_opening_shape= (shape>-1 ? shape : choose_opening_shape());
1620
1621 2563 int32_t w=framebuf->w, h=framebuf->h;
1622 2563 int32_t blockrows=h/8, blockcolumns=32;
1623 2563 int32_t xoffset=(x-(w/2))/8, yoffset=(y-(h/2))/8;
1624
1625
2/2
✓ Branch 0 taken 71876 times.
✓ Branch 1 taken 2563 times.
74439 for(int32_t blockrow=0; blockrow<blockrows; ++blockrow) //30
1626 {
1627
2/2
✓ Branch 0 taken 2300032 times.
✓ Branch 1 taken 71876 times.
2371908 for(int32_t blockcolumn=0; blockcolumn<blockcolumns; ++blockcolumn) //40
1628 {
1629
2/2
✓ Branch 0 taken 1133766 times.
✓ Branch 1 taken 1166266 times.
2300032 screen_triangles[blockrow][blockcolumn]=zc_max(abs(int32_t(double(blockcolumns-1)/2-blockcolumn+xoffset)),abs(int32_t(double(blockrows-1)/2-blockrow+yoffset)))|0x0100|((blockrow-yoffset<blockrows/2)?0:0x8000)|((blockcolumn-xoffset<blockcolumns/2)?0x4000:0);
1630 2300032 }
1631 71876 }
1632
1633 2563 black_opening_count = -66;
1634 2563 black_opening_x = x;
1635 2563 black_opening_y = y;
1636 2563 lensclk = 0;
1637
1/2
✓ Branch 0 taken 2563 times.
✗ Branch 1 not taken.
2563 if(black_opening_shape == bosFADEBLACK)
1638 {
1639 refreshTints();
1640 memcpy(tempblackpal, RAMpal, sizeof(RAMpal)); //Store palette in temp palette for fade effect
1641 }
1642
2/2
✓ Branch 0 taken 361 times.
✓ Branch 1 taken 2202 times.
2563 if(wait)
1643 {
1644 2202 FFCore.warpScriptCheck();
1645
2/2
✓ Branch 0 taken 2201 times.
✓ Branch 1 taken 145343 times.
147544 for(int32_t i=0; i<66; i++)
1646 {
1647 145343 draw_screen();
1648 145343 advanceframe(true);
1649
1650
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 145342 times.
145343 if(Quit)
1651 {
1652 1 break;
1653 }
1654 145342 }
1655 2202 }
1656 2563 }
1657
1658 217619 void black_opening(BITMAP *dest,int32_t x,int32_t y,int32_t a,int32_t max_a)
1659 {
1660 217619 clear_to_color(tmp_scr,BLACK);
1661 217619 int32_t w=dest->w, h=dest->h;
1662
1663
4/6
✗ Branch 0 not taken.
✓ Branch 1 taken 9636 times.
✓ Branch 2 taken 1980 times.
✓ Branch 3 taken 20328 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 185675 times.
217619 switch(black_opening_shape)
1664 {
1665 case bosOVAL:
1666 {
1667 9636 double new_w=(w/2)+abs(w/2-x);
1668 9636 double new_h=(h/2)+abs(h/2-y);
1669 9636 double b=sqrt(((new_w*new_w)/4)+(new_h*new_h));
1670 9636 ellipsefill(tmp_scr,x,y,int32_t(2*a*b/max_a)/8*8,int32_t(a*b/max_a)/8*8,0);
1671 9636 break;
1672 }
1673
1674 case bosTRIANGLE:
1675 {
1676 1980 double new_w=(w/2)+abs(w/2-x);
1677 1980 double new_h=(h/2)+abs(h/2-y);
1678 1980 double r=a*(new_w*sqrt((double)3)+new_h)/max_a;
1679 1980 double P2= (PI/2);
1680 1980 double P23=(2*PI/3);
1681 1980 double P43=(4*PI/3);
1682 1980 double Pa= (-4*PI*a/(3*max_a));
1683 1980 double angle=P2+Pa;
1684 1980 double a0=angle;
1685 1980 double a2=angle+P23;
1686 1980 double a4=angle+P43;
1687 3960 triangle(tmp_scr, x+int32_t(zc::math::Cos(a0)*r), y-int32_t(zc::math::Sin(a0)*r),
1688 1980 x+int32_t(zc::math::Cos(a2)*r), y-int32_t(zc::math::Sin(a2)*r),
1689 1980 x+int32_t(zc::math::Cos(a4)*r), y-int32_t(zc::math::Sin(a4)*r),
1690 0);
1691 1980 break;
1692 }
1693
1694 case bosSMAS:
1695 {
1696
2/2
✓ Branch 0 taken 7260 times.
✓ Branch 1 taken 13068 times.
20328 int32_t distance=zc_max(abs(w/2-x),abs(h/2-y))/8;
1697
1698
2/2
✓ Branch 0 taken 569184 times.
✓ Branch 1 taken 20328 times.
589512 for(int32_t blockrow=0; blockrow<h/8; ++blockrow) //30
1699 {
1700
2/2
✓ Branch 0 taken 4553472 times.
✓ Branch 1 taken 569184 times.
5122656 for(int32_t linerow=0; linerow<8; ++linerow)
1701 {
1702 4553472 qword *triangleline=(qword*)(tmp_scr->line[(blockrow*8+linerow)]);
1703
1704
2/2
✓ Branch 0 taken 145711104 times.
✓ Branch 1 taken 4553472 times.
150264576 for(int32_t blockcolumn=0; blockcolumn<32; ++blockcolumn) //40
1705 {
1706 437133312 *triangleline=triangles[(screen_triangles[blockrow][blockcolumn]&0xC000)>>14]
1707
6/6
✓ Branch 0 taken 105268072 times.
✓ Branch 1 taken 40443032 times.
✓ Branch 2 taken 96140976 times.
✓ Branch 3 taken 49570128 times.
✓ Branch 4 taken 55697944 times.
✓ Branch 5 taken 40443032 times.
145711104 [zc_min(zc_max((((31+distance)*(max_a-a)/max_a)+((screen_triangles[blockrow][blockcolumn]&0x0FFF)-0x0100)-(15+distance)),0),15)]
1708 145711104 [linerow];
1709 145711104 ++triangleline;
1710 145711104 }
1711 4553472 }
1712 569184 }
1713
1714 20328 break;
1715 }
1716
1717 case bosFADEBLACK:
1718 {
1719 if(black_opening_count<0)
1720 {
1721 black_fade(zc_min(-black_opening_count,63));
1722 }
1723 else if(black_opening_count>0)
1724 {
1725 black_fade(63-zc_max(black_opening_count-3,0));
1726 }
1727 else black_fade(0);
1728 return; //no blitting from tmp_scr!
1729 }
1730
1731 185675 case bosCIRCLE:
1732 default:
1733 {
1734 185675 double new_w=(w/2)+abs(w/2-x);
1735 185675 double new_h=(h/2)+abs(h/2-y);
1736 185675 int32_t r=int32_t(sqrt((new_w*new_w)+(new_h*new_h))*a/max_a);
1737 //circlefill(tmp_scr,x,y,a<<3,0);
1738 185675 circlefill(tmp_scr,x,y,r,0);
1739 185675 break;
1740 }
1741 }
1742
1743 217619 masked_blit(tmp_scr,dest,0,0,0,0,320,240);
1744 217619 }
1745
1746 // fadeamnt is 0-63
1747 void black_fade(int32_t fadeamnt)
1748 {
1749 fadeamnt = _rgb_scale_6[fadeamnt];
1750 for(int32_t i=0; i < 0xEF; i++)
1751 {
1752 RAMpal[i].r = vbound(tempblackpal[i].r-fadeamnt,0,255);
1753 RAMpal[i].g = vbound(tempblackpal[i].g-fadeamnt,0,255);
1754 RAMpal[i].b = vbound(tempblackpal[i].b-fadeamnt,0,255);
1755 }
1756
1757 refreshpal = true;
1758 }
1759
1760 //----------------------------------------------------------------
1761
1762 201552057 bool item_disabled(int32_t item) //is this item disabled?
1763 {
1764
2/2
✓ Branch 0 taken 14531591 times.
✓ Branch 1 taken 187020466 times.
201552057 return (unsigned(item) < MAXITEMS && game->items_off[item] != 0);
1765 }
1766
1767 15644362 bool can_use_item(int32_t item_type, int32_t item) //can Hero use this item?
1768 {
1769
2/2
✓ Branch 0 taken 254624 times.
✓ Branch 1 taken 15389738 times.
15644362 if(current_item(item_type, true) >=item)
1770 {
1771 254624 return true;
1772 }
1773
1774 15389738 return false;
1775 15644362 }
1776
1777 43606786 bool has_item(int32_t item_type, int32_t it) //does Hero possess this item?
1778 {
1779
5/9
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421290 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 337472 times.
✓ Branch 6 taken 28752509 times.
✓ Branch 7 taken 9900449 times.
✓ Branch 8 taken 195066 times.
43606786 switch(item_type)
1780 {
1781 case itype_bomb:
1782 case itype_sbomb:
1783 {
1784 int32_t itemid = getItemID(itemsbuf, item_type, it);
1785
1786 if(itemid == -1)
1787 return false;
1788
1789 return (game->get_item(itemid));
1790 }
1791
1792 case itype_clock:
1793 {
1794 4421290 int32_t itemid = getItemID(itemsbuf, item_type, it);
1795
1796
2/4
✓ Branch 0 taken 4421290 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4421290 times.
✗ Branch 3 not taken.
4421290 if(itemid != -1 && (itemsbuf[itemid].flags & item_flag1)) //Active clock
1797 return (game->get_item(itemid));
1798 4421290 return Hero.getClock()?1:0;
1799 }
1800
1801 case itype_key:
1802 return (game->get_keys()>0);
1803
1804 case itype_magiccontainer:
1805 return (game->get_maxmagic()>=game->get_mp_per_block());
1806
1807 case itype_triforcepiece: //it: -2=any, -1=current level, other=that level
1808 {
1809
1/3
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
337472 switch(it)
1810 {
1811 case -2:
1812 {
1813 for(int32_t i=0; i<MAXLEVELS; i++)
1814 {
1815 if(game->lvlitems[i]&(1 << li_mcguffin))
1816 {
1817 return true;
1818 }
1819 }
1820
1821 return false;
1822 }
1823
1824 case -1:
1825 return (game->lvlitems[dlevel]&(1 << li_mcguffin));
1826
1827 default:
1828
2/4
✓ Branch 0 taken 337472 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 337472 times.
337472 if(it>=0&&it<MAXLEVELS)
1829 {
1830 337472 return (game->lvlitems[it]&(1 << li_mcguffin));
1831 }
1832
1833 break;
1834 }
1835
1836 return 0;
1837 }
1838
1839 case itype_map: //it: -2=any, -1=current level, other=that level
1840 {
1841
2/3
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 28210883 times.
28752509 switch(it)
1842 {
1843 case -2:
1844 {
1845 for(int32_t i=0; i<MAXLEVELS; i++)
1846 {
1847 if(game->lvlitems[i]&(1 << li_map))
1848 {
1849 return true;
1850 }
1851 }
1852
1853 return false;
1854 }
1855
1856 case -1:
1857 28210883 return (game->lvlitems[dlevel]&(1 << li_map))!=0;
1858
1859 default:
1860
2/4
✓ Branch 0 taken 541626 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 541626 times.
541626 if(it>=0&&it<MAXLEVELS)
1861 {
1862 541626 return (game->lvlitems[it]&(1 << li_map))!=0;
1863 }
1864
1865 break;
1866 }
1867
1868 return 0;
1869 }
1870
1871 case itype_compass: //it: -2=any, -1=current level, other=that level
1872 {
1873
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 9900449 times.
9900449 switch(it)
1874 {
1875 case -2:
1876 {
1877 for(int32_t i=0; i<MAXLEVELS; i++)
1878 {
1879 if(game->lvlitems[i]&(1 << li_compass))
1880 {
1881 return true;
1882 }
1883 }
1884
1885 return false;
1886 }
1887
1888 case -1:
1889 9900449 return (game->lvlitems[dlevel]&(1 << li_compass))!=0;
1890
1891 default:
1892 if(it>=0&&it<MAXLEVELS)
1893 {
1894 return (game->lvlitems[it]&(1 << li_compass))!=0;
1895 }
1896
1897 break;
1898 }
1899 return 0;
1900 }
1901
1902 case itype_bosskey: //it: -2=any, -1=current level, other=that level
1903 {
1904
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 195066 times.
195066 switch(it)
1905 {
1906 case -2:
1907 {
1908 for(int32_t i=0; i<MAXLEVELS; i++)
1909 {
1910 if(game->lvlitems[i]&(1 << li_boss_key))
1911 {
1912 return true;
1913 }
1914 }
1915
1916 return false;
1917 }
1918
1919 case -1:
1920 195066 return (game->lvlitems[dlevel]&(1 << li_boss_key))?1:0;
1921
1922 default:
1923 if(it>=0&&it<MAXLEVELS)
1924 {
1925 return (game->lvlitems[it]&(1 << li_boss_key))?1:0;
1926 }
1927 break;
1928 }
1929 return 0;
1930 }
1931
1932 default:
1933 int32_t itemid = getItemID(itemsbuf, item_type, it);
1934
1935 if(itemid == -1)
1936 return false;
1937
1938 return game->get_item(itemid);
1939 }
1940 43606786 }
1941
1942 150981041 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
1943 {
1944
9/9
✓ Branch 0 taken 4421290 times.
✓ Branch 1 taken 115610721 times.
✓ Branch 2 taken 4421290 times.
✓ Branch 3 taken 4421290 times.
✓ Branch 4 taken 4421290 times.
✓ Branch 5 taken 4421290 times.
✓ Branch 6 taken 4421290 times.
✓ Branch 7 taken 4421290 times.
✓ Branch 8 taken 4421290 times.
150981041 switch(item_type)
1945 {
1946 case itype_clock:
1947 {
1948 4421290 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
1949
1950
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 4421290 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4421290 if(maxid != -1 && (itemsbuf[maxid].flags & item_flag1)) //Active clock
1951 return itemsbuf[maxid].level;
1952
1953 4421290 return has_item(itype_clock,1) ? 1 : 0;
1954 }
1955
1956 case itype_key:
1957 4421290 return game->get_keys();
1958
1959 case itype_lkey:
1960 4421290 return game->lvlkeys[get_dlevel()];
1961
1962 case itype_magiccontainer:
1963 4421290 return game->get_maxmagic()/game->get_mp_per_block();
1964
1965 case itype_triforcepiece:
1966 {
1967 4421290 int count=0;
1968
1969
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
1970 {
1971 2263700480 count+=(game->lvlitems[i]&(1 << li_mcguffin))?1:0;
1972 2263700480 }
1973
1974 4421290 return count;
1975 }
1976
1977 case itype_map:
1978 {
1979 4421290 int count=0;
1980
1981
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
1982 {
1983 2263700480 count+=(game->lvlitems[i]&(1 << li_map))?1:0;
1984 2263700480 }
1985
1986 4421290 return count;
1987 }
1988
1989 case itype_compass:
1990 {
1991 4421290 int count=0;
1992
1993
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
1994 {
1995 2263700480 count+=(game->lvlitems[i]&(1 << li_compass))?1:0;
1996 2263700480 }
1997
1998 4421290 return count;
1999 }
2000
2001 case itype_bosskey:
2002 {
2003 4421290 int count=0;
2004
2005
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int i=0; i<MAXLEVELS; i++)
2006 {
2007 2263700480 count+=(game->lvlitems[i]&(1 << li_boss_key))?1:0;
2008 2263700480 }
2009
2010 4421290 return count;
2011 }
2012
2013 default:
2014 115610721 int maxid = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
2015
2016
2/2
✓ Branch 0 taken 81917743 times.
✓ Branch 1 taken 33692978 times.
115610721 if(maxid == -1)
2017 81917743 return 0;
2018
2019 33692978 return itemsbuf[maxid].level;
2020 }
2021 150981041 }
2022
2023 414 std::map<int32_t, int32_t> itemcache;
2024 414 std::map<int32_t, int32_t> itemcache_cost;
2025
2026 void removeFromItemCache(int32_t itemclass)
2027 {
2028 itemcache.erase(itemclass);
2029 itemcache_cost.erase(itemclass);
2030 cache_tile_mod_clear();
2031 }
2032
2033 13059050 void flushItemCache(bool justcost)
2034 {
2035 13059050 itemcache_cost.clear();
2036
2/2
✓ Branch 0 taken 12985420 times.
✓ Branch 1 taken 73630 times.
13059050 if(!justcost)
2037 73630 itemcache.clear();
2038
2/2
✓ Branch 0 taken 6357348 times.
✓ Branch 1 taken 6628072 times.
12985420 else if(replay_version_check(0,19))
2039 6357348 return;
2040
2041 6701702 cache_tile_mod_clear();
2042
2043 //also fix the active subscreen if items were deleted -DD
2044
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6701702 times.
6701702 if(game != NULL)
2045 {
2046 6701702 verifyBothWeapons();
2047 6701702 refresh_subscr_items();
2048 6701702 }
2049 13059050 }
2050
2051 // This is used often, so it should be as direct as possible.
2052 3070008012 int _c_item_id_internal(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2053 {
2054 3070008012 bool use_cost_cache = replay_version_check(19);
2055
2/2
✓ Branch 0 taken 2929876684 times.
✓ Branch 1 taken 140131328 times.
3070008012 if(jinx_check)
2056 {
2057 //special case for shields...
2058
3/4
✓ Branch 0 taken 54383156 times.
✓ Branch 1 taken 85748172 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 54383156 times.
140131328 if (itemtype == itype_shield && !HeroShieldClk())
2059 54383156 jinx_check = false;
2060
4/4
✓ Branch 0 taken 52645673 times.
✓ Branch 1 taken 33102499 times.
✓ Branch 2 taken 10990568 times.
✓ Branch 3 taken 41655105 times.
85748172 else if(!(HeroSwordClk() || HeroItemClk()))
2061 41655105 jinx_check = false; //not jinxed
2062 140131328 }
2063
4/4
✓ Branch 0 taken 125094 times.
✓ Branch 1 taken 3069882918 times.
✓ Branch 2 taken 1853 times.
✓ Branch 3 taken 123241 times.
3070008012 if(!Hero.BunnyClock() || itemtype == itype_pearl) // bunny_check does not apply
2064 3069884771 check_bunny = false;
2065
2/2
✓ Branch 0 taken 3012249416 times.
✓ Branch 1 taken 57758596 times.
3070008012 if(itemtype == itype_ring) checkmagic = true;
2066
4/4
✓ Branch 0 taken 3025914945 times.
✓ Branch 1 taken 44093067 times.
✓ Branch 2 taken 320798885 times.
✓ Branch 3 taken 25152461 times.
3415959358 if (!jinx_check && !check_bunny
2067
4/4
✓ Branch 0 taken 3025819312 times.
✓ Branch 1 taken 95633 times.
✓ Branch 2 taken 345951346 times.
✓ Branch 3 taken 2679867966 times.
3025914945 && (use_cost_cache || itemtype != itype_ring))
2068 {
2069
4/4
✓ Branch 0 taken 607185676 times.
✓ Branch 1 taken 2393481175 times.
✓ Branch 2 taken 270318411 times.
✓ Branch 3 taken 336867265 times.
3000666851 auto& cache = checkmagic && use_cost_cache ? itemcache_cost : itemcache;
2070 3000666851 auto res = cache.find(itemtype);
2071
2072
2/2
✓ Branch 0 taken 2849727357 times.
✓ Branch 1 taken 150939494 times.
3000666851 if(res != cache.end())
2073 2849727357 return res->second;
2074 150939494 }
2075
2076 220280655 int result = -1;
2077 220280655 int highestlevel = -1;
2078
2079
2/2
✓ Branch 0 taken 56391847680 times.
✓ Branch 1 taken 220280655 times.
56612128335 for(int i=0; i<MAXITEMS; i++)
2080 {
2081
6/6
✓ Branch 0 taken 6184727968 times.
✓ Branch 1 taken 50207119712 times.
✓ Branch 2 taken 96488169 times.
✓ Branch 3 taken 6088239799 times.
✓ Branch 4 taken 82048 times.
✓ Branch 5 taken 96406121 times.
56391847680 if(game->get_item(i) && itemsbuf[i].type==itemtype && !item_disabled(i))
2082 {
2083
4/4
✓ Branch 0 taken 91731626 times.
✓ Branch 1 taken 4674495 times.
✓ Branch 2 taken 2473305 times.
✓ Branch 3 taken 89258321 times.
96406121 if(checkmagic && itemtype != itype_magicring)
2084
2/2
✓ Branch 0 taken 89257620 times.
✓ Branch 1 taken 701 times.
89258321 if(!checkmagiccost(i))
2085 701 continue;
2086
6/6
✓ Branch 0 taken 88805441 times.
✓ Branch 1 taken 7599979 times.
✓ Branch 2 taken 1257252 times.
✓ Branch 3 taken 6342727 times.
✓ Branch 4 taken 4147756 times.
✓ Branch 5 taken 3452223 times.
96405420 if(jinx_check && (usesSwordJinx(i) ? HeroSwordClk() : HeroItemClk()))
2087
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3452223 times.
3452223 if(!(itemsbuf[i].flags & item_jinx_immune))
2088 3452223 continue;
2089
3/4
✓ Branch 0 taken 100571 times.
✓ Branch 1 taken 92852626 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100571 times.
92953197 if(check_bunny && !checkbunny(i))
2090 100571 continue;
2091
2092
2/2
✓ Branch 0 taken 8438993 times.
✓ Branch 1 taken 84413633 times.
92852626 if(itemsbuf[i].level >= highestlevel)
2093 {
2094 84413633 highestlevel = itemsbuf[i].level;
2095 84413633 result=i;
2096 84413633 }
2097 92852626 }
2098 56388294185 }
2099
2100
4/4
✓ Branch 0 taken 176187588 times.
✓ Branch 1 taken 44093067 times.
✓ Branch 2 taken 95633 times.
✓ Branch 3 taken 176091955 times.
220280655 if(!(jinx_check || check_bunny)) //Can't cache jinx_check/check_bunny
2101 {
2102
2/2
✓ Branch 0 taken 134323968 times.
✓ Branch 1 taken 41767987 times.
176091955 if (use_cost_cache)
2103 {
2104
2/2
✓ Branch 0 taken 118410431 times.
✓ Branch 1 taken 15913537 times.
134323968 if (!checkmagic)
2105 15913537 itemcache[itemtype] = result;
2106
6/6
✓ Branch 0 taken 15913537 times.
✓ Branch 1 taken 118410431 times.
✓ Branch 2 taken 688507 times.
✓ Branch 3 taken 15225030 times.
✓ Branch 4 taken 673546 times.
✓ Branch 5 taken 14961 times.
134323968 if (checkmagic || result < 0 || checkmagiccost(result))
2107 134309007 itemcache_cost[itemtype] = result;
2108 134323968 }
2109 else
2110 {
2111 41767987 itemcache[itemtype] = result;
2112 }
2113 176091955 }
2114 220280655 return result;
2115 3070008012 }
2116
2117 // 'jinx_check' indicates that the highest level item *immune to jinxes* should be returned.
2118 3043222822 int current_item_id(int itype, bool checkmagic, bool jinx_check, bool check_bunny)
2119 {
2120
3/4
✓ Branch 0 taken 3026417069 times.
✓ Branch 1 taken 16805753 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3026417069 times.
3043222822 if(itype < 0 || itype >= itype_max) return -1;
2121
1/2
✓ Branch 0 taken 3026417069 times.
✗ Branch 1 not taken.
3026417069 if(game->OverrideItems[itype] > -2)
2122 {
2123 auto ovid = game->OverrideItems[itype];
2124 if(ovid < 0 || ovid >= MAXITEMS)
2125 return -1;
2126 if(itemsbuf[ovid].type == itype)
2127 {
2128 if(itype == itype_magicring)
2129 checkmagic = false;
2130 else if(itype == itype_ring)
2131 checkmagic = true;
2132
2133 if(checkmagic && !checkmagiccost(ovid))
2134 return -1;
2135
2136 if (jinx_check && !checkitem_jinx(ovid))
2137 {
2138 return -1;
2139 }
2140 return ovid;
2141 }
2142 }
2143 3026417069 auto ret = _c_item_id_internal(itype,checkmagic,jinx_check,check_bunny);
2144
2/2
✓ Branch 0 taken 96540385 times.
✓ Branch 1 taken 2929876684 times.
3026417069 if(!jinx_check) //If not already a jinx-immune-only check...
2145 {
2146 //And the player IS jinxed...
2147
2/2
✓ Branch 0 taken 2886285741 times.
✓ Branch 1 taken 43590943 times.
2929876684 if(HeroIsJinxed())
2148 {
2149 //Then do a jinx-immune-only check here
2150 43590943 auto ret2 = _c_item_id_internal(itype,checkmagic,true,check_bunny);
2151 //And *IF IT FINDS A VALID ITEM*, return that one instead! -Em
2152 //Should NOT need a compat rule, as this should always return -1 in old quests.
2153
2/2
✓ Branch 0 taken 3266237 times.
✓ Branch 1 taken 40324706 times.
43590943 if(ret2 > -1) return ret2;
2154 40324706 }
2155 2926610447 }
2156 3023150832 return ret;
2157 3043222822 }
2158
2159 66324047 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
2160 {
2161 66324047 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
2162
2/2
✓ Branch 0 taken 35516653 times.
✓ Branch 1 taken 30807394 times.
66324047 return (result<0) ? 0 : itemsbuf[result].power;
2163 }
2164
2165 26 int32_t heart_container_id()
2166 {
2167
1/2
✓ Branch 0 taken 754 times.
✗ Branch 1 not taken.
754 for(int32_t i=0; i<MAXITEMS; i++)
2168 {
2169
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 728 times.
754 if(itemsbuf[i].type == itype_heartcontainer)
2170 {
2171 26 return i;
2172 }
2173 728 }
2174 return -1;
2175 26 }
2176
2177 struct tilemod_cache_state_t
2178 {
2179
6/6
✓ Branch 0 taken 4420934 times.
✓ Branch 1 taken 8540300 times.
✓ Branch 2 taken 2 times.
✓ Branch 3 taken 8540298 times.
✓ Branch 4 taken 354 times.
✓ Branch 5 taken 8539944 times.
21501534 bool operator==(const tilemod_cache_state_t&) const = default;
2180
2181 bool valid;
2182 bool bunny_clock;
2183 bool superman;
2184 int shield;
2185 };
2186 tilemod_cache_state_t tilemod_cache_state;
2187 int32_t tilemod_cache_value;
2188
2189 6703253 void cache_tile_mod_clear()
2190 {
2191 6703253 tilemod_cache_state = {false};
2192 6703253 }
2193
2194 12961234 int32_t item_tile_mod()
2195 {
2196 51844936 tilemod_cache_state_t state = {
2197 .valid = true,
2198 12961234 .bunny_clock = Hero.BunnyClock() != 0,
2199 12961234 .superman = Hero.superman,
2200 12961234 .shield = Hero.active_shield_id,
2201 };
2202
2/2
✓ Branch 0 taken 8539944 times.
✓ Branch 1 taken 4421290 times.
12961234 if (tilemod_cache_state == state)
2203 8539944 return tilemod_cache_value;
2204
2205 4421290 int32_t tile=0;
2206 4421290 bool check_bombcost = !get_qr(qr_BROKEN_BOMB_AMMO_COSTS);
2207
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413298 times.
✓ Branch 2 taken 3079194 times.
✓ Branch 3 taken 928798 times.
4421290 if(check_bombcost || game->get_bombs())
2208 {
2209 3492492 int32_t itemid = current_item_id(itype_bomb,check_bombcost);
2210
3/4
✓ Branch 0 taken 3432971 times.
✓ Branch 1 taken 59521 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3432971 times.
3492492 if(itemid > -1 && checkbunny(itemid))
2211 3432971 tile+=itemsbuf[itemid].ltm;
2212 3492492 }
2213
2214
4/4
✓ Branch 0 taken 4007992 times.
✓ Branch 1 taken 413298 times.
✓ Branch 2 taken 965298 times.
✓ Branch 3 taken 3042694 times.
4421290 if(check_bombcost || game->get_sbombs())
2215 {
2216 1378596 int32_t itemid = current_item_id(itype_sbomb,check_bombcost);
2217
3/4
✓ Branch 0 taken 965057 times.
✓ Branch 1 taken 413539 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 965057 times.
1378596 if(itemid > -1 && checkbunny(itemid))
2218 965057 tile+=itemsbuf[itemid].ltm;
2219 1378596 }
2220
2221
2/2
✓ Branch 0 taken 4408554 times.
✓ Branch 1 taken 12736 times.
4421290 if(current_item(itype_clock))
2222 {
2223 12736 int32_t itemid =
2224
2/2
✓ Branch 0 taken 12704 times.
✓ Branch 1 taken 32 times.
12736 get_qr(qr_HARDCODED_LITEM_LTMS)
2225 ? iClock
2226 32 : getHighestLevelEvenUnowned(itemsbuf, itype_clock);
2227
2/4
✓ Branch 0 taken 12736 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 12736 times.
12736 if(itemid > -1 && checkbunny(itemid))
2228 12736 tile+=itemsbuf[itemid].ltm;
2229 12736 }
2230
2231
2/2
✓ Branch 0 taken 3775648 times.
✓ Branch 1 taken 645642 times.
4421290 if(current_item(itype_key))
2232 {
2233 645642 int32_t itemid =
2234
2/2
✓ Branch 0 taken 608640 times.
✓ Branch 1 taken 37002 times.
645642 get_qr(qr_HARDCODED_LITEM_LTMS)
2235 ? iKey
2236 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_key);
2237
2/4
✓ Branch 0 taken 645642 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 645642 times.
645642 if(itemid > -1 && checkbunny(itemid))
2238 645642 tile+=itemsbuf[itemid].ltm;
2239 645642 }
2240
2241
2/2
✓ Branch 0 taken 3920406 times.
✓ Branch 1 taken 500884 times.
4421290 if(current_item(itype_lkey))
2242 {
2243 500884 int32_t itemid =
2244
2/2
✓ Branch 0 taken 414169 times.
✓ Branch 1 taken 86715 times.
500884 get_qr(qr_HARDCODED_LITEM_LTMS)
2245 ? iLevelKey
2246 86715 : getHighestLevelEvenUnowned(itemsbuf, itype_lkey);
2247
2/4
✓ Branch 0 taken 500884 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 500884 times.
500884 if(itemid > -1 && checkbunny(itemid))
2248 500884 tile+=itemsbuf[itemid].ltm;
2249 500884 }
2250
2251
2/2
✓ Branch 0 taken 1586460 times.
✓ Branch 1 taken 2834830 times.
4421290 if(current_item(itype_map))
2252 {
2253 2834830 int32_t itemid =
2254
2/2
✓ Branch 0 taken 2823834 times.
✓ Branch 1 taken 10996 times.
2834830 get_qr(qr_HARDCODED_LITEM_LTMS)
2255 ? iMap
2256 10996 : getHighestLevelEvenUnowned(itemsbuf, itype_map);
2257
2/4
✓ Branch 0 taken 2834830 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2834830 times.
2834830 if(itemid > -1 && checkbunny(itemid))
2258 2834830 tile+=itemsbuf[itemid].ltm;
2259 2834830 }
2260
2261
2/2
✓ Branch 0 taken 2109301 times.
✓ Branch 1 taken 2311989 times.
4421290 if(current_item(itype_compass))
2262 {
2263 2311989 int32_t itemid =
2264
2/2
✓ Branch 0 taken 2295941 times.
✓ Branch 1 taken 16048 times.
2311989 get_qr(qr_HARDCODED_LITEM_LTMS)
2265 ? iCompass
2266 16048 : getHighestLevelEvenUnowned(itemsbuf, itype_compass);
2267
2/4
✓ Branch 0 taken 2311989 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2311989 times.
2311989 if(itemid > -1 && checkbunny(itemid))
2268 2311989 tile+=itemsbuf[itemid].ltm;
2269 2311989 }
2270
2271
2/2
✓ Branch 0 taken 1334874 times.
✓ Branch 1 taken 3086416 times.
4421290 if(current_item(itype_bosskey))
2272 {
2273 3086416 int32_t itemid =
2274
2/2
✓ Branch 0 taken 2993139 times.
✓ Branch 1 taken 93277 times.
3086416 get_qr(qr_HARDCODED_LITEM_LTMS)
2275 ? iBossKey
2276 93277 : getHighestLevelEvenUnowned(itemsbuf, itype_bosskey);
2277
2/4
✓ Branch 0 taken 3086416 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3086416 times.
3086416 if(itemid > -1 && checkbunny(itemid))
2278 3086416 tile+=itemsbuf[itemid].ltm;
2279 3086416 }
2280
2281
2/2
✓ Branch 0 taken 48296 times.
✓ Branch 1 taken 4372994 times.
4421290 if(current_item(itype_magiccontainer))
2282 {
2283 4372994 int32_t itemid =
2284
2/2
✓ Branch 0 taken 3904336 times.
✓ Branch 1 taken 468658 times.
4372994 get_qr(qr_HARDCODED_LITEM_LTMS)
2285 ? iMagicC
2286 468658 : getHighestLevelEvenUnowned(itemsbuf, itype_magiccontainer);
2287
3/4
✓ Branch 0 taken 4372994 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 17 times.
✓ Branch 3 taken 4372977 times.
4372994 if(itemid > -1 && checkbunny(itemid))
2288 4372977 tile+=itemsbuf[itemid].ltm;
2289 4372994 }
2290
2291
2/2
✓ Branch 0 taken 1314810 times.
✓ Branch 1 taken 3106480 times.
4421290 if(current_item(itype_triforcepiece))
2292 {
2293 3106480 int32_t itemid =
2294
2/2
✓ Branch 0 taken 3069478 times.
✓ Branch 1 taken 37002 times.
3106480 get_qr(qr_HARDCODED_LITEM_LTMS)
2295 ? iTriforce
2296 37002 : getHighestLevelEvenUnowned(itemsbuf, itype_triforcepiece);
2297
2/4
✓ Branch 0 taken 3106480 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 3106480 times.
3106480 if(itemid > -1 && checkbunny(itemid))
2298 3106480 tile+=itemsbuf[itemid].ltm;
2299 3106480 }
2300
2301
2/2
✓ Branch 0 taken 2263700480 times.
✓ Branch 1 taken 4421290 times.
2268121770 for(int32_t i=0; i<itype_max; i++)
2302 {
2303
2/2
✓ Branch 0 taken 2023628800 times.
✓ Branch 1 taken 240071680 times.
2263700480 if(!get_qr(qr_HARDCODED_LITEM_LTMS))
2304 {
2305
2/2
✓ Branch 0 taken 4688900 times.
✓ Branch 1 taken 235382780 times.
240071680 switch(i)
2306 {
2307 case itype_bomb:
2308 case itype_sbomb:
2309 case itype_clock:
2310 case itype_key:
2311 case itype_lkey:
2312 case itype_map:
2313 case itype_compass:
2314 case itype_bosskey:
2315 case itype_magiccontainer:
2316 case itype_triforcepiece:
2317 4688900 continue; //already handled
2318 }
2319 235382780 }
2320 2259011580 int32_t itemid = current_item_id(i,false);
2321
2/2
✓ Branch 0 taken 2254590290 times.
✓ Branch 1 taken 4421290 times.
2259011580 if(i == itype_shield)
2322 4421290 itemid = getCurrentShield(false);
2323
2324
4/4
✓ Branch 0 taken 115677549 times.
✓ Branch 1 taken 2143334031 times.
✓ Branch 2 taken 1 times.
✓ Branch 3 taken 115677548 times.
2259011580 if(itemid < 0 || !checkbunny(itemid))
2325 2143334032 continue;
2326
2327 115677548 itemdata const& itm = itemsbuf[itemid];
2328
2329
2/2
✓ Branch 0 taken 111976845 times.
✓ Branch 1 taken 3700703 times.
115677548 switch(itm.type)
2330 {
2331 case itype_shield:
2332
1/2
✓ Branch 0 taken 3700703 times.
✗ Branch 1 not taken.
3700703 if(itm.flags & item_flag9) //active shield
2333 {
2334 if(!usingActiveShield(itemid))
2335 {
2336 tile+=itm.misc6; //'Inactive PTM'
2337 continue;
2338 }
2339 }
2340 3700703 break;
2341 }
2342
2343 115677548 tile+=itm.ltm;
2344 115677548 }
2345
2346 4421290 tilemod_cache_value = tile;
2347 4421290 tilemod_cache_state = state;
2348 4421290 return tile;
2349 12961234 }
2350
2351 12961234 int32_t bunny_tile_mod()
2352 {
2353
2/2
✓ Branch 0 taken 1870 times.
✓ Branch 1 taken 12959364 times.
12961234 if(Hero.BunnyClock())
2354 {
2355 1870 return game->get_bunny_ltm();
2356 }
2357 12959364 return 0;
2358 12961234 }
2359
2360 // Hints are drawn on a separate layer to combo reveals.
2361 // TODO: move out of zc_sys.cpp, weird place for this code.
2362 20058 void draw_lens_under(BITMAP *dest, bool layer)
2363 {
2364 //Lens flag 1: Replacement for qr_LENSHINTS; if set, lens will show hints. Does nothing if flag 2 is set.
2365 //Lens flag 2: Disable "hints", prevent rendering of Secret Combos
2366 //Lens flag 3: Don't show armos/chest/dive items
2367 //Lens flag 4: Show Raft Paths
2368 //Lens flag 5: Show Invisible Enemies
2369
4/4
✓ Branch 0 taken 19602 times.
✓ Branch 1 taken 456 times.
✓ Branch 2 taken 9801 times.
✓ Branch 3 taken 9801 times.
20058 bool hints = (itemsbuf[Hero.getLastLensID()].flags & item_flag2) ? false : (layer && (itemsbuf[Hero.getLastLensID()].flags & item_flag1));
2370
2371 20058 int32_t strike_hint_table[11]=
2372 {
2373 mfARROW, mfBOMB, mfBRANG, mfWANDMAGIC,
2374 mfSWORD, mfREFMAGIC, mfHOOKSHOT,
2375 mfREFFIREBALL, mfHAMMER, mfSWORDBEAM, mfWAND
2376 };
2377
2378 {
2379 20058 int32_t blink_rate=flash_reduction_enabled()?6:1;
2380 20058 int32_t tempitem, tempweapon=0;
2381 20058 strike_hint=strike_hint_table[strike_hint_counter];
2382
2383
2/2
✓ Branch 0 taken 19459 times.
✓ Branch 1 taken 599 times.
20058 if(strike_hint_timer>32)
2384 {
2385 599 strike_hint_timer=0;
2386 599 strike_hint_counter=((strike_hint_counter+1)%11);
2387 599 }
2388
2389 20058 ++strike_hint_timer;
2390
2391 3550266 for_every_visible_rpos_layer0([&](const rpos_handle_t& rpos_handle) {
2392 3530208 mapscr* scr = rpos_handle.scr;
2393 7306676 auto [x, y] = rpos_handle.xy();
2394 7060416 y += playing_field_offset;
2395
2396 3530208 int32_t tempitemx=-16, tempitemy=-16;
2397 3530208 int32_t tempweaponx=-16, tempweapony=-16;
2398
2399
2/2
✓ Branch 0 taken 7060416 times.
✓ Branch 1 taken 3530208 times.
10590624 for(int32_t iter=0; iter<2; ++iter)
2400 {
2401 7060416 int32_t checkflag=0;
2402
2403
2/2
✓ Branch 0 taken 3530208 times.
✓ Branch 1 taken 3530208 times.
7060416 if(iter==0)
2404 {
2405 3530208 checkflag = rpos_handle.cflag();
2406 3530208 }
2407 else
2408 {
2409 3530208 checkflag = rpos_handle.sflag();
2410 }
2411
2412
2/2
✓ Branch 0 taken 7059318 times.
✓ Branch 1 taken 1098 times.
7060416 if(checkflag==mfSTRIKE)
2413 {
2414
2/2
✓ Branch 0 taken 192 times.
✓ Branch 1 taken 906 times.
1098 if(!hints)
2415 {
2416
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSTRIKE],scr->secretcset[sSTRIKE]);
2417 906 }
2418 else
2419 {
2420 192 checkflag = strike_hint;
2421 }
2422 1098 }
2423
2424
21/36
✓ Branch 0 taken 6911766 times.
✓ Branch 1 taken 3258 times.
✓ Branch 2 taken 108898 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2602 times.
✓ Branch 5 taken 28750 times.
✓ Branch 6 taken 2418 times.
✓ Branch 7 taken 504 times.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✓ Branch 11 taken 814 times.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✓ Branch 14 taken 93 times.
✓ Branch 15 taken 96 times.
✓ Branch 16 taken 24 times.
✓ Branch 17 taken 25 times.
✗ Branch 18 not taken.
✗ Branch 19 not taken.
✓ Branch 20 taken 138 times.
✓ Branch 21 taken 16 times.
✓ Branch 22 taken 16 times.
✓ Branch 23 taken 7 times.
✗ Branch 24 not taken.
✗ Branch 25 not taken.
✗ Branch 26 not taken.
✓ Branch 27 taken 16 times.
✗ Branch 28 not taken.
✗ Branch 29 not taken.
✗ Branch 30 not taken.
✓ Branch 31 taken 17 times.
✓ Branch 32 taken 35 times.
✓ Branch 33 taken 17 times.
✗ Branch 34 not taken.
✓ Branch 35 taken 906 times.
7060416 switch(checkflag)
2425 {
2426 case 0:
2427 case mfZELDA:
2428 case mfPUSHED:
2429 case mfENEMY0:
2430 case mfENEMY1:
2431 case mfENEMY2:
2432 case mfENEMY3:
2433 case mfENEMY4:
2434 case mfENEMY5:
2435 case mfENEMY6:
2436 case mfENEMY7:
2437 case mfENEMY8:
2438 case mfENEMY9:
2439 case mfSINGLE:
2440 case mfSINGLE16:
2441 case mfNOENEMY:
2442 case mfTRAP_H:
2443 case mfTRAP_V:
2444 case mfTRAP_4:
2445 case mfTRAP_LR:
2446 case mfTRAP_UD:
2447 case mfNOGROUNDENEMY:
2448 case mfNOBLOCKS:
2449 case mfSCRIPT1:
2450 case mfSCRIPT2:
2451 case mfSCRIPT3:
2452 case mfSCRIPT4:
2453 case mfSCRIPT5:
2454 case mfSCRIPT6:
2455 case mfSCRIPT7:
2456 case mfSCRIPT8:
2457 case mfSCRIPT9:
2458 case mfSCRIPT10:
2459 case mfSCRIPT11:
2460 case mfSCRIPT12:
2461 case mfSCRIPT13:
2462 case mfSCRIPT14:
2463 case mfSCRIPT15:
2464 case mfSCRIPT16:
2465 case mfSCRIPT17:
2466 case mfSCRIPT18:
2467 case mfSCRIPT19:
2468 case mfSCRIPT20:
2469 case mfPITHOLE:
2470 case mfPITFALLFLOOR:
2471 case mfLAVA:
2472 case mfICE:
2473 case mfICEDAMAGE:
2474 case mfDAMAGE1:
2475 case mfDAMAGE2:
2476 case mfDAMAGE4:
2477 case mfDAMAGE8:
2478 case mfDAMAGE16:
2479 case mfDAMAGE32:
2480 case mfFREEZEALL:
2481 case mfFREZEALLANSFFCS:
2482 case mfFREEZEFFCSOLY:
2483 case mfSCRITPTW1TRIG:
2484 case mfSCRITPTW2TRIG:
2485 case mfSCRITPTW3TRIG:
2486 case mfSCRITPTW4TRIG:
2487 case mfSCRITPTW5TRIG:
2488 case mfSCRITPTW6TRIG:
2489 case mfSCRITPTW7TRIG:
2490 case mfSCRITPTW8TRIG:
2491 case mfSCRITPTW9TRIG:
2492 case mfSCRITPTW10TRIG:
2493 case mfTROWEL:
2494 case mfTROWELNEXT:
2495 case mfTROWELSPECIALITEM:
2496 case mfSLASHPOT:
2497 case mfLIFTPOT:
2498 case mfLIFTORSLASH:
2499 case mfLIFTROCK:
2500 case mfLIFTROCKHEAVY:
2501 case mfDROPITEM:
2502 case mfSPECIALITEM:
2503 case mfDROPKEY:
2504 case mfDROPLKEY:
2505 case mfDROPCOMPASS:
2506 case mfDROPMAP:
2507 case mfDROPBOSSKEY:
2508 case mfSPAWNNPC:
2509 case mfSWITCHHOOK:
2510 case mfSIDEVIEWLADDER:
2511 case mfSIDEVIEWPLATFORM:
2512 case mfNOENEMYSPAWN:
2513 case mfENEMYALL:
2514 case mfNOMIRROR:
2515 case mfUNSAFEGROUND:
2516 case mf168:
2517 case mf169:
2518 case mf170:
2519 case mf171:
2520 case mf172:
2521 case mf173:
2522 case mf174:
2523 case mf175:
2524 case mf176:
2525 case mf177:
2526 case mf178:
2527 case mf179:
2528 case mf180:
2529 case mf181:
2530 case mf182:
2531 case mf183:
2532 case mf184:
2533 case mf185:
2534 case mf186:
2535 case mf187:
2536 case mf188:
2537 case mf189:
2538 case mf190:
2539 case mf191:
2540 case mf192:
2541 case mf193:
2542 case mf194:
2543 case mf195:
2544 case mf196:
2545 case mf197:
2546 case mf198:
2547 case mf199:
2548 case mf200:
2549 case mf201:
2550 case mf202:
2551 case mf203:
2552 case mf204:
2553 case mf205:
2554 case mf206:
2555 case mf207:
2556 case mf208:
2557 case mf209:
2558 case mf210:
2559 case mf211:
2560 case mf212:
2561 case mf213:
2562 case mf214:
2563 case mf215:
2564 case mf216:
2565 case mf217:
2566 case mf218:
2567 case mf219:
2568 case mf220:
2569 case mf221:
2570 case mf222:
2571 case mf223:
2572 case mf224:
2573 case mf225:
2574 case mf226:
2575 case mf227:
2576 case mf228:
2577 case mf229:
2578 case mf230:
2579 case mf231:
2580 case mf232:
2581 case mf233:
2582 case mf234:
2583 case mf235:
2584 case mf236:
2585 case mf237:
2586 case mf238:
2587 case mf239:
2588 case mf240:
2589 case mf241:
2590 case mf242:
2591 case mf243:
2592 case mf244:
2593 case mf245:
2594 case mf246:
2595 case mf247:
2596 case mf248:
2597 case mf249:
2598 case mf250:
2599 case mf251:
2600 case mf252:
2601 case mf253:
2602 case mf254:
2603 case mfEXTENDED:
2604 6911766 break;
2605
2606 case mfPUSHUD:
2607 case mfPUSHLR:
2608 case mfPUSH4:
2609 case mfPUSHU:
2610 case mfPUSHD:
2611 case mfPUSHL:
2612 case mfPUSHR:
2613 case mfPUSHUDNS:
2614 case mfPUSHLRNS:
2615 case mfPUSH4NS:
2616 case mfPUSHUNS:
2617 case mfPUSHDNS:
2618 case mfPUSHLNS:
2619 case mfPUSHRNS:
2620 case mfPUSHUDINS:
2621 case mfPUSHLRINS:
2622 case mfPUSH4INS:
2623 case mfPUSHUINS:
2624 case mfPUSHDINS:
2625 case mfPUSHLINS:
2626 case mfPUSHRINS:
2627
3/4
✓ Branch 0 taken 1939 times.
✓ Branch 1 taken 1319 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
3258 if(!hints && ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&16))
2628
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 1939 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1939 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
1939 || ((get_debug() && zc_getkey(KEY_N)) && (frame&16))))
2629 {
2630 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->undercombo,scr->undercset);
2631 }
2632
2633
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 3258 times.
3258 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2634
3/6
✓ Branch 0 taken 2520 times.
✓ Branch 1 taken 738 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 738 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
3258 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2635 {
2636
2/2
✓ Branch 0 taken 1488 times.
✓ Branch 1 taken 1032 times.
2520 if(hints)
2637 {
2638
3/3
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 63 times.
✓ Branch 2 taken 897 times.
1032 switch (rpos_handle.ctype())
2639 {
2640 case cPUSH_HEAVY:
2641 case cPUSH_HW:
2642 72 tempitem=getItemIDPower(itemsbuf,itype_bracelet,1);
2643 144 tempitemx=x, tempitemy=y;
2644
2645
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 if(tempitem>-1)
2646 72 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2647
2648 72 break;
2649
2650 case cPUSH_HEAVY2:
2651 case cPUSH_HW2:
2652 63 tempitem=getItemIDPower(itemsbuf,itype_bracelet,2);
2653 126 tempitemx=x, tempitemy=y;
2654
2655
1/2
✓ Branch 0 taken 63 times.
✗ Branch 1 not taken.
63 if(tempitem>-1)
2656 63 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2657
2658 63 break;
2659 }
2660 1032 }
2661 2520 }
2662
2663 3258 break;
2664
2665 case mfWHISTLE:
2666
1/2
✓ Branch 0 taken 2418 times.
✗ Branch 1 not taken.
2418 if(hints)
2667 {
2668 tempitem=getItemID(itemsbuf,itype_whistle,1);
2669
2670 if(tempitem<0) break;
2671
2672 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2673 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2674 {
2675 tempitemx=x;
2676 tempitemy=y;
2677 }
2678
2679 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2680 }
2681
2682 2418 break;
2683
2684 //Why is this here?
2685 case mfFAIRY:
2686 case mfMAGICFAIRY:
2687 case mfALLFAIRY:
2688 if(hints)
2689 {
2690 tempitem=getItemID(itemsbuf, itype_fairy,1);//iFairyMoving;
2691
2692 if(tempitem < 0) break;
2693
2694 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2695 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2696 {
2697 tempitemx=x;
2698 tempitemy=y;
2699 }
2700
2701 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2702 }
2703
2704 break;
2705
2706 case mfANYFIRE:
2707
2/2
✓ Branch 0 taken 252 times.
✓ Branch 1 taken 252 times.
504 if(!hints)
2708 {
2709
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBCANDLE],scr->secretcset[sBCANDLE]);
2710 252 }
2711 else
2712 {
2713 252 tempitem=getItemID(itemsbuf,itype_candle,1);
2714
2715
1/2
✓ Branch 0 taken 252 times.
✗ Branch 1 not taken.
252 if(tempitem<0) break;
2716
2717
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 252 times.
252 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2718
3/6
✓ Branch 0 taken 189 times.
✓ Branch 1 taken 63 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 63 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
252 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2719 {
2720 189 tempitemx=x;
2721 189 tempitemy=y;
2722 189 }
2723
2724 252 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2725 }
2726
2727 504 break;
2728
2729 case mfSTRONGFIRE:
2730 if(!hints)
2731 {
2732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sRCANDLE],scr->secretcset[sRCANDLE]);
2733 }
2734 else
2735 {
2736 tempitem=getItemID(itemsbuf,itype_candle,2);
2737
2738 if(tempitem<0) break;
2739
2740 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2741 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2742 {
2743 tempitemx=x;
2744 tempitemy=y;
2745 }
2746
2747 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2748 }
2749
2750 break;
2751
2752 case mfMAGICFIRE:
2753 if(!hints)
2754 {
2755 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDFIRE],scr->secretcset[sWANDFIRE]);
2756 }
2757 else
2758 {
2759 tempitem=getItemID(itemsbuf,itype_wand,1);
2760
2761 if(tempitem<0) break;
2762
2763 tempweapon=wFire;
2764
2765 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2766 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2767 {
2768 tempitemx=x;
2769 tempitemy=y;
2770 }
2771 else
2772 {
2773 tempweaponx=x;
2774 tempweapony=y;
2775 }
2776
2777 putweapon(dest,tempweaponx,tempweapony,tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2778 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2779 }
2780
2781 break;
2782
2783 case mfDIVINEFIRE:
2784 if(!hints)
2785 {
2786 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sDIVINEFIRE],scr->secretcset[sDIVINEFIRE]);
2787 }
2788 else
2789 {
2790 tempitem=getItemID(itemsbuf,itype_divinefire,1);
2791
2792 if(tempitem<0) break;
2793
2794 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2795 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2796 {
2797 tempitemx=x;
2798 tempitemy=y;
2799 }
2800
2801 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2802 }
2803
2804 break;
2805
2806 case mfARROW:
2807
2/2
✓ Branch 0 taken 82 times.
✓ Branch 1 taken 732 times.
814 if(!hints)
2808 {
2809
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 732 times.
732 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sARROW],scr->secretcset[sARROW]);
2810 732 }
2811 else
2812 {
2813 82 tempitem=getItemID(itemsbuf,itype_arrow,1);
2814
2815
1/2
✓ Branch 0 taken 82 times.
✗ Branch 1 not taken.
82 if(tempitem<0) break;
2816
2817
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 82 times.
82 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2818
3/6
✓ Branch 0 taken 61 times.
✓ Branch 1 taken 21 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 21 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
82 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2819 {
2820 61 tempitemx=x;
2821 61 tempitemy=y;
2822 61 }
2823
2824 82 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2825 }
2826
2827 814 break;
2828
2829 case mfSARROW:
2830 if(!hints)
2831 {
2832 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSARROW],scr->secretcset[sSARROW]);
2833 }
2834 else
2835 {
2836 tempitem=getItemID(itemsbuf,itype_arrow,2);
2837
2838 if(tempitem<0) break;
2839
2840 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2841 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2842 {
2843 tempitemx=x;
2844 tempitemy=y;
2845 }
2846
2847 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2848 }
2849
2850 break;
2851
2852 case mfGARROW:
2853 if(!hints)
2854 {
2855 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sGARROW],scr->secretcset[sGARROW]);
2856 }
2857 else
2858 {
2859 tempitem=getItemID(itemsbuf,itype_arrow,3);
2860
2861 if(tempitem<0) break;
2862
2863 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2864 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2865 {
2866 tempitemx=x;
2867 tempitemy=y;
2868 }
2869
2870 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2871 }
2872
2873 break;
2874
2875 case mfBOMB:
2876
2/2
✓ Branch 0 taken 17 times.
✓ Branch 1 taken 76 times.
93 if(!hints)
2877 {
2878
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 76 times.
76 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sBOMB],scr->secretcset[sBOMB]);
2879 76 }
2880 else
2881 {
2882 //tempitem=getItemID(itemsbuf,itype_bomb,1);
2883 17 tempweapon = wLitBomb;
2884
2885 //if (tempitem<0) break;
2886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2887
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2888 {
2889 12 tempweaponx=x;
2890 12 tempweapony=y;
2891 12 }
2892
2893 17 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2894 }
2895
2896 93 break;
2897
2898 case mfSBOMB:
2899
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 48 times.
96 if(!hints)
2900 {
2901
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSBOMB],scr->secretcset[sSBOMB]);
2902 48 }
2903 else
2904 {
2905 //tempitem=getItemID(itemsbuf,itype_sbomb,1);
2906 //if (tempitem<0) break;
2907 48 tempweapon = wLitSBomb;
2908
2909
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2910
3/6
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 12 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 12 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2911 {
2912 36 tempweaponx=x;
2913 36 tempweapony=y;
2914 36 }
2915
2916 48 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
2917 }
2918
2919 96 break;
2920
2921 case mfARMOS_SECRET:
2922
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 12 times.
24 if(!hints)
2923 {
2924
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 12 times.
12 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2925 36 putcombo(dest,x,y,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
2926 12 }
2927 24 break;
2928
2929 case mfBRANG:
2930
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 20 times.
25 if(!hints)
2931 {
2932
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
2933 60 putcombo(dest,x,y,scr->secretcombo[sBRANG],scr->secretcset[sBRANG]);
2934 20 }
2935 else
2936 {
2937 5 tempitem=getItemID(itemsbuf,itype_brang,1);
2938
2939
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 if(tempitem<0) break;
2940
2941
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2942
3/6
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
5 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2943 {
2944 4 tempitemx=x;
2945 4 tempitemy=y;
2946 4 }
2947
2948 5 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2949 }
2950
2951 25 break;
2952
2953 case mfMBRANG:
2954 if(!hints)
2955 {
2956 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMBRANG],scr->secretcset[sMBRANG]);
2957 }
2958 else
2959 {
2960 tempitem=getItemID(itemsbuf,itype_brang,2);
2961
2962 if(tempitem<0) break;
2963
2964 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2965 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2966 {
2967 tempitemx=x;
2968 tempitemy=y;
2969 }
2970
2971 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2972 }
2973
2974 break;
2975
2976 case mfFBRANG:
2977 if(!hints)
2978 {
2979 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sFBRANG],scr->secretcset[sFBRANG]);
2980 }
2981 else
2982 {
2983 tempitem=getItemID(itemsbuf,itype_brang,3);
2984
2985 if(tempitem<0) break;
2986
2987 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
2988 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
2989 {
2990 tempitemx=x;
2991 tempitemy=y;
2992 }
2993
2994 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
2995 }
2996
2997 break;
2998
2999 case mfWANDMAGIC:
3000
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!hints)
3001 {
3002
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 138 times.
138 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWANDMAGIC],scr->secretcset[sWANDMAGIC]);
3003 138 }
3004 else
3005 {
3006 tempitem=getItemID(itemsbuf,itype_wand,1);
3007
3008 if(tempitem<0) break;
3009
3010 tempweapon=itemsbuf[tempitem].wpn3;
3011
3012 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3013 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3014 {
3015 tempitemx=x;
3016 tempitemy=y;
3017 }
3018 else
3019 {
3020 tempweaponx=x;
3021 tempweapony=y;
3022 --lens_hint_weapon[wMagic][4];
3023
3024 if(lens_hint_weapon[wMagic][4]<-8)
3025 {
3026 lens_hint_weapon[wMagic][4]=8;
3027 }
3028 }
3029
3030 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3031 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3032 }
3033
3034 138 break;
3035
3036 case mfREFMAGIC:
3037
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3038 {
3039 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFMAGIC],scr->secretcset[sREFMAGIC]);
3040 }
3041 else
3042 {
3043 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3044
3045
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3046
3047 16 tempweapon=ewMagic;
3048
3049
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3050
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 3 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3051 {
3052 13 tempitemx=x;
3053 13 tempitemy=y;
3054 13 }
3055 else
3056 {
3057 3 tempweaponx=x;
3058 3 tempweapony=y;
3059
3060
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
3 if(lens_hint_weapon[ewMagic][2]==up)
3061 {
3062 1 --lens_hint_weapon[ewMagic][4];
3063 1 }
3064 else
3065 {
3066 2 ++lens_hint_weapon[ewMagic][4];
3067 }
3068
3069
1/2
✓ Branch 0 taken 3 times.
✗ Branch 1 not taken.
3 if(lens_hint_weapon[ewMagic][4]>8)
3070 {
3071 lens_hint_weapon[ewMagic][2]=up;
3072 }
3073
3074
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 2 times.
3 if(lens_hint_weapon[ewMagic][4]<=0)
3075 {
3076 2 lens_hint_weapon[ewMagic][2]=down;
3077 2 }
3078 }
3079
3080 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3081 16 putweapon(dest,tempweaponx,tempweapony+lens_hint_weapon[tempweapon][4],tempweapon, 0, lens_hint_weapon[ewMagic][2], lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3082 }
3083
3084 16 break;
3085
3086 case mfREFFIREBALL:
3087
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3088 {
3089 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sREFFIREBALL],scr->secretcset[sREFFIREBALL]);
3090 }
3091 else
3092 {
3093 16 tempitem=getItemID(itemsbuf,itype_shield,3);
3094
3095
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3096
3097 16 tempweapon=ewFireball;
3098
3099
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3100
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3101 {
3102 12 tempitemx=x;
3103 12 tempitemy=y;
3104 12 tempweaponx=x;
3105 12 tempweapony=y;
3106 12 ++lens_hint_weapon[ewFireball][3];
3107
3108
2/2
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 1 times.
12 if(lens_hint_weapon[ewFireball][3]>8)
3109 {
3110 1 lens_hint_weapon[ewFireball][3]=-8;
3111 1 lens_hint_weapon[ewFireball][4]=8;
3112 1 }
3113
3114
2/2
✓ Branch 0 taken 8 times.
✓ Branch 1 taken 4 times.
12 if(lens_hint_weapon[ewFireball][3]>0)
3115 {
3116 8 ++lens_hint_weapon[ewFireball][4];
3117 8 }
3118 else
3119 {
3120 4 --lens_hint_weapon[ewFireball][4];
3121 }
3122 12 }
3123
3124 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3125 16 putweapon(dest,tempweaponx+lens_hint_weapon[tempweapon][3],tempweapony+lens_hint_weapon[ewFireball][4],tempweapon, 0, up, lens_hint_weapon[tempweapon][0], lens_hint_weapon[tempweapon][1],-1);
3126 }
3127
3128 16 break;
3129
3130 case mfSWORD:
3131
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(!hints)
3132 {
3133 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORD],scr->secretcset[sSWORD]);
3134 }
3135 else
3136 {
3137 7 tempitem=getItemID(itemsbuf,itype_sword,1);
3138
3139
1/2
✓ Branch 0 taken 7 times.
✗ Branch 1 not taken.
7 if(tempitem<0) break;
3140
3141
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7 times.
7 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3142
3/6
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
7 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3143 {
3144 5 tempitemx=x;
3145 5 tempitemy=y;
3146 5 }
3147
3148 7 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3149 }
3150
3151 7 break;
3152
3153 case mfWSWORD:
3154 if(!hints)
3155 {
3156 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORD],scr->secretcset[sWSWORD]);
3157 }
3158 else
3159 {
3160 tempitem=getItemID(itemsbuf,itype_sword,2);
3161
3162 if(tempitem<0) break;
3163
3164 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3165 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3166 {
3167 tempitemx=x;
3168 tempitemy=y;
3169 }
3170
3171 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3172 }
3173
3174 break;
3175
3176 case mfMSWORD:
3177 if(!hints)
3178 {
3179 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORD],scr->secretcset[sMSWORD]);
3180 }
3181 else
3182 {
3183 tempitem=getItemID(itemsbuf,itype_sword,3);
3184
3185 if(tempitem<0) break;
3186
3187 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3188 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3189 {
3190 tempitemx=x;
3191 tempitemy=y;
3192 }
3193
3194 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3195 }
3196
3197 break;
3198
3199 case mfXSWORD:
3200 if(!hints)
3201 {
3202 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORD],scr->secretcset[sXSWORD]);
3203 }
3204 else
3205 {
3206 tempitem=getItemID(itemsbuf,itype_sword,4);
3207
3208 if(tempitem<0) break;
3209
3210 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3211 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3212 {
3213 tempitemx=x;
3214 tempitemy=y;
3215 }
3216
3217 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3218 }
3219
3220 break;
3221
3222 case mfSWORDBEAM:
3223
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!hints)
3224 {
3225 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sSWORDBEAM],scr->secretcset[sSWORDBEAM]);
3226 }
3227 else
3228 {
3229 16 tempitem=getItemID(itemsbuf,itype_sword,1);
3230
3231
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(tempitem<0) break;
3232
3233
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
16 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3234
3/6
✓ Branch 0 taken 11 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3235 {
3236 11 tempitemx=x;
3237 11 tempitemy=y;
3238 11 }
3239
3240 16 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 1);
3241 }
3242
3243 16 break;
3244
3245 case mfWSWORDBEAM:
3246 if(!hints)
3247 {
3248 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWSWORDBEAM],scr->secretcset[sWSWORDBEAM]);
3249 }
3250 else
3251 {
3252 tempitem=getItemID(itemsbuf,itype_sword,2);
3253
3254 if(tempitem<0) break;
3255
3256 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3257 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3258 {
3259 tempitemx=x;
3260 tempitemy=y;
3261 }
3262
3263 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 2);
3264 }
3265
3266 break;
3267
3268 case mfMSWORDBEAM:
3269 if(!hints)
3270 {
3271 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sMSWORDBEAM],scr->secretcset[sMSWORDBEAM]);
3272 }
3273 else
3274 {
3275 tempitem=getItemID(itemsbuf,itype_sword,3);
3276
3277 if(tempitem<0) break;
3278
3279 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3280 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3281 {
3282 tempitemx=x;
3283 tempitemy=y;
3284 }
3285
3286 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 3);
3287 }
3288
3289 break;
3290
3291 case mfXSWORDBEAM:
3292 if(!hints)
3293 {
3294 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sXSWORDBEAM],scr->secretcset[sXSWORDBEAM]);
3295 }
3296 else
3297 {
3298 tempitem=getItemID(itemsbuf,itype_sword,4);
3299
3300 if(tempitem<0) break;
3301
3302 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3303 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3304 {
3305 tempitemx=x;
3306 tempitemy=y;
3307 }
3308
3309 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 4);
3310 }
3311
3312 break;
3313
3314 case mfHOOKSHOT:
3315
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3316 {
3317 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHOOKSHOT],scr->secretcset[sHOOKSHOT]);
3318 }
3319 else
3320 {
3321 17 tempitem=getItemID(itemsbuf,itype_hookshot,1);
3322
3323
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3324
3325
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3326
3/6
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 5 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3327 {
3328 12 tempitemx=x;
3329 12 tempitemy=y;
3330 12 }
3331
3332 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3333 }
3334
3335 17 break;
3336
3337 case mfWAND:
3338
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(!hints)
3339 {
3340 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sWAND],scr->secretcset[sWAND]);
3341 }
3342 else
3343 {
3344 35 tempitem=getItemID(itemsbuf,itype_wand,1);
3345
3346
1/2
✓ Branch 0 taken 35 times.
✗ Branch 1 not taken.
35 if(tempitem<0) break;
3347
3348
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 35 times.
35 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3349
3/6
✓ Branch 0 taken 28 times.
✓ Branch 1 taken 7 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 7 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
35 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3350 {
3351 28 tempitemx=x;
3352 28 tempitemy=y;
3353 28 }
3354
3355 35 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3356 }
3357
3358 35 break;
3359
3360 case mfHAMMER:
3361
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(!hints)
3362 {
3363 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))putcombo(dest,x,y,scr->secretcombo[sHAMMER],scr->secretcset[sHAMMER]);
3364 }
3365 else
3366 {
3367 17 tempitem=getItemID(itemsbuf,itype_hammer,1);
3368
3369
1/2
✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
17 if(tempitem<0) break;
3370
3371
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
17 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate))
3372
3/6
✓ Branch 0 taken 13 times.
✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 4 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
17 || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3373 {
3374 13 tempitemx=x;
3375 13 tempitemy=y;
3376 13 }
3377
3378 17 putitem2(dest,tempitemx,tempitemy,tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3379 }
3380
3381 17 break;
3382
3383 case mfARMOS_ITEM:
3384 case mfDIVE_ITEM:
3385 {
3386
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
2602 int flag = (cur_screen < 128 && get_qr(qr_ITEMPICKUPSETSBELOW)) ? mITEM : mSPECIALITEM;
3387
2/4
✗ Branch 0 not taken.
✓ Branch 1 taken 2602 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2602 times.
2602 if((!getmapflag(scr, flag) || (scr->flags9&fBELOWRETURN)) && !(itemsbuf[Hero.getLastLensID()].flags & item_flag3))
3388 {
3389 7806 putitem2(dest,x,y,scr->catchall, lens_hint_item[scr->catchall][0], lens_hint_item[scr->catchall][1], 0);
3390 2602 }
3391 2602 break;
3392 }
3393
3394 case 16:
3395 case 17:
3396 case 18:
3397 case 19:
3398 case 20:
3399 case 21:
3400 case 22:
3401 case 23:
3402 case 24:
3403 case 25:
3404 case 26:
3405 case 27:
3406 case 28:
3407 case 29:
3408 case 30:
3409 case 31:
3410
2/2
✓ Branch 0 taken 1008 times.
✓ Branch 1 taken 107890 times.
108898 if(!hints)
3411
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 107890 times.
215780 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3412 323670 putcombo(dest,x,y,scr->secretcombo[checkflag-16+4],scr->secretcset[checkflag-16+4]);
3413
3414 108898 break;
3415 case mfSECRETSNEXT:
3416 if(!hints)
3417 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3418 putcombo(dest,x,y,rpos_handle.data()+1,rpos_handle.cset());
3419
3420 break;
3421
3422 case mfSTRIKE:
3423
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 906 times.
906 if(!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3424 {
3425 906 goto special;
3426 }
3427 else
3428 {
3429 break;
3430 }
3431
3432 28750 default: goto special;
3433
3434 special:
3435
8/8
✓ Branch 0 taken 14732 times.
✓ Branch 1 taken 14924 times.
✓ Branch 2 taken 528 times.
✓ Branch 3 taken 14204 times.
✓ Branch 4 taken 496 times.
✓ Branch 5 taken 32 times.
✓ Branch 6 taken 6108 times.
✓ Branch 7 taken 8128 times.
29656 if(layer && ((checkflag!=mfRAFT && checkflag!=mfRAFT_BRANCH&& checkflag!=mfRAFT_BOUNCE) ||(itemsbuf[Hero.getLastLensID()].flags & item_flag4)))
3436 {
3437
4/8
✗ Branch 0 not taken.
✓ Branch 1 taken 6604 times.
✓ Branch 2 taken 4954 times.
✓ Branch 3 taken 1650 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 1650 times.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
6604 if((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&blink_rate)) || ((get_debug() && zc_getkey(KEY_N)) && (frame&blink_rate)))
3438 {
3439 24770 rectfill(dest,x,y,x+15,y+15,WHITE);
3440 4954 }
3441 6604 }
3442
3443 29656 break;
3444 }
3445 7060416 }
3446 3530208 });
3447
3448 40116 for_every_base_screen_in_region([&](mapscr* scr, unsigned int region_scr_x, unsigned int region_scr_y) {
3449 90824 auto [offx, offy] = translate_screen_coordinates_to_world(scr->screen);
3450
3451 40116 offx -= viewport.x;
3452 40116 offy -= viewport.y;
3453 40116 offy += playing_field_offset;
3454
3455
2/2
✓ Branch 0 taken 10029 times.
✓ Branch 1 taken 10029 times.
20058 if (layer)
3456 {
3457
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 359 times.
10029 if (scr->door[0]==dWALK)
3458 1795 rectfill(dest, 120+offx, 16+offy, 135+offx, 31+offy, WHITE);
3459
3460
2/2
✓ Branch 0 taken 9606 times.
✓ Branch 1 taken 423 times.
10029 if (scr->door[1]==dWALK)
3461 2115 rectfill(dest, 120+offx, 144+offy, 135+offx, 159+offy, WHITE);
3462
3463
2/2
✓ Branch 0 taken 9447 times.
✓ Branch 1 taken 582 times.
10029 if (scr->door[2]==dWALK)
3464 2910 rectfill(dest, 16+offx, 80+offy, 31+offx, 95+offy, WHITE);
3465
3466
2/2
✓ Branch 0 taken 9405 times.
✓ Branch 1 taken 624 times.
10029 if (scr->door[3]==dWALK)
3467 3120 rectfill(dest, 224+offx, 80+offy, 239+offx, 95+offy, WHITE);
3468
3469
2/2
✓ Branch 0 taken 9986 times.
✓ Branch 1 taken 43 times.
10029 if (scr->door[0]==dBOMB)
3470 {
3471 129 showbombeddoor(scr, dest, 0, offx, offy);
3472 43 }
3473
3474
2/2
✓ Branch 0 taken 9990 times.
✓ Branch 1 taken 39 times.
10029 if (scr->door[1]==dBOMB)
3475 {
3476 117 showbombeddoor(scr, dest, 1, offx, offy);
3477 39 }
3478
3479
2/2
✓ Branch 0 taken 10023 times.
✓ Branch 1 taken 6 times.
10029 if (scr->door[2]==dBOMB)
3480 {
3481 18 showbombeddoor(scr, dest, 2, offx, offy);
3482 6 }
3483
3484
2/2
✓ Branch 0 taken 9992 times.
✓ Branch 1 taken 37 times.
10029 if (scr->door[3]==dBOMB)
3485 {
3486 111 showbombeddoor(scr, dest, 3, offx, offy);
3487 37 }
3488 10029 }
3489
3490
3/4
✓ Branch 0 taken 18024 times.
✓ Branch 1 taken 2034 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18024 times.
20058 if (scr->stairx || scr->stairy)
3491 {
3492
2/2
✓ Branch 0 taken 911 times.
✓ Branch 1 taken 1123 times.
2034 if (!hints)
3493 {
3494
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1123 times.
1123 if (!(itemsbuf[Hero.getLastLensID()].flags & item_flag2))
3495 3369 putcombo(dest,scr->stairx+offx,scr->stairy+offy,scr->secretcombo[sSTAIRS],scr->secretcset[sSTAIRS]);
3496 1123 }
3497 else
3498 {
3499
2/2
✓ Branch 0 taken 863 times.
✓ Branch 1 taken 48 times.
911 if(scr->flags&fWHISTLE)
3500 {
3501 48 tempitem=getItemID(itemsbuf,itype_whistle,1);
3502 48 int32_t tempitemx=-16+offx;
3503 48 int32_t tempitemy=-16+offy-playing_field_offset;
3504
3505
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 48 times.
48 if ((!(get_debug() && zc_getkey(KEY_N)) && (lensclk&(blink_rate/4)))
3506
3/6
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 24 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 24 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
48 || ((get_debug() && zc_getkey(KEY_N)) && (frame&(blink_rate/4))))
3507 {
3508 48 tempitemx=scr->stairx+offx;
3509 48 tempitemy=scr->stairy+offy;
3510 24 }
3511
3512 48 putitem2(dest, tempitemx, tempitemy, tempitem, lens_hint_item[tempitem][0], lens_hint_item[tempitem][1], 0);
3513 48 }
3514 }
3515 2034 }
3516 20058 });
3517 }
3518 20058 }
3519
3520 9690 void draw_lens_over()
3521 {
3522 9690 int w = 288;
3523 9690 int h = 240;
3524
3525
4/6
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9672 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18 times.
✓ Branch 4 taken 18 times.
✗ Branch 5 not taken.
9690 static BITMAP *lens_scr = create_bitmap_ex(8,2*w,2*h);
3526 static int32_t last_width = -1;
3527 9690 int32_t width = itemsbuf[current_item_id(itype_lens,true)].misc1;
3528
3529 // Only redraw the circle if the size has changed
3530
2/2
✓ Branch 0 taken 9670 times.
✓ Branch 1 taken 20 times.
9690 if (width != last_width)
3531 {
3532 20 clear_to_color(lens_scr, BLACK);
3533 20 circlefill(lens_scr, w, h, width, 0);
3534 20 circle(lens_scr, w, h, width+2, 0);
3535 20 circle(lens_scr, w, h, width+5, 0);
3536 20 last_width=width;
3537 20 }
3538
3539 9690 masked_blit(lens_scr, framebuf, w-(HeroX()+8)+viewport.x, h-(HeroY()+8)+viewport.y, 0, playing_field_offset, 256, viewport.h);
3540 9690 do_primitives(framebuf, SPLAYER_LENS_OVER);
3541 9690 }
3542
3543 37074404 static void update_bmp_size(BITMAP** bmp_ptr, int w, int h)
3544 {
3545 37074404 BITMAP* bmp = *bmp_ptr;
3546
3/4
✓ Branch 0 taken 37074404 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 37074398 times.
✓ Branch 3 taken 6 times.
37074404 if (bmp->w == w && bmp->h == h)
3547 37074398 return;
3548
3549 6 int depth = bitmap_color_depth(bmp);
3550 6 destroy_bitmap(bmp);
3551 6 *bmp_ptr = create_bitmap_ex(depth, w, h);
3552 37074404 }
3553
3554 32028 void draw_wavy(BITMAP *source, BITMAP *target, int32_t amplitude, bool interpol)
3555 {
3556
4/6
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 32022 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
✓ Branch 4 taken 6 times.
✗ Branch 5 not taken.
32028 static BITMAP *wavebuf = create_bitmap_ex(8,288,240-original_playing_field_offset);
3557 32028 update_bmp_size(&wavebuf, 288, 240 - original_playing_field_offset);
3558
3559 32028 clear_to_color(wavebuf, BLACK);
3560 32028 blit(source,wavebuf,0,original_playing_field_offset,16,0,256,framebuf->h-original_playing_field_offset);
3561
3562 int32_t ofs;
3563
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 32028 times.
32028 amplitude = zc_min(2048,amplitude); // some arbitrary limit to prevent crashing
3564
4/6
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
✓ Branch 4 taken 606 times.
✓ Branch 5 taken 31422 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY)) amplitude = zc_min(16,amplitude);
3565 32028 int32_t amp2 = viewport.visible_height(show_bottom_8px);
3566
2/4
✓ Branch 0 taken 32028 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 32028 times.
32028 if(flash_reduction_enabled() && !get_qr(qr_WAVY_NO_EPILEPSY_2)) amp2*=2;
3567 32028 int32_t i=frame%amp2;
3568
3569
2/2
✓ Branch 0 taken 5382552 times.
✓ Branch 1 taken 32028 times.
5414580 for(int32_t j=0; j<viewport.visible_height(show_bottom_8px); j++)
3570 {
3571
3/4
✓ Branch 0 taken 2691276 times.
✓ Branch 1 taken 2691276 times.
✓ Branch 2 taken 2691276 times.
✗ Branch 3 not taken.
5382552 if(j&1 && interpol)
3572 {
3573 // Add 288*2048 to ensure it's never negative. It'll get modded out.
3574 ofs=288*2048+int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3575 }
3576 else
3577 {
3578 5382552 ofs=288*2048-int32_t(zc::math::Sin((double(i+j)*2*PI/amp2))*amplitude);
3579 }
3580
3581
1/2
✓ Branch 0 taken 5382552 times.
✗ Branch 1 not taken.
5382552 if(ofs)
3582 {
3583
2/2
✓ Branch 0 taken 1377933312 times.
✓ Branch 1 taken 5382552 times.
1383315864 for(int32_t k=0; k<256; k++)
3584 {
3585 1377933312 target->line[j+original_playing_field_offset][k]=wavebuf->line[j][(k+ofs+16)%288];
3586 1377933312 }
3587 5382552 }
3588 5382552 }
3589 32028 }
3590
3591 28272 void draw_fuzzy(int32_t fuzz)
3592 // draws from right half of scrollbuf to framebuf
3593 {
3594 int32_t firstx, firsty, xstep, ystep, i, y, dx, dy;
3595 byte *start, *si, *di;
3596
3597
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 28272 times.
28272 if(fuzz<1)
3598 fuzz = 1;
3599
3600 28272 xstep = 128%fuzz;
3601
3602
2/2
✓ Branch 0 taken 5890 times.
✓ Branch 1 taken 22382 times.
28272 if(xstep > 0)
3603 22382 xstep = fuzz-xstep;
3604
3605 28272 ystep = 112%fuzz;
3606
3607
2/2
✓ Branch 0 taken 8246 times.
✓ Branch 1 taken 20026 times.
28272 if(ystep > 0)
3608 20026 ystep = fuzz-ystep;
3609
3610 28272 firsty = 1;
3611
3612
2/2
✓ Branch 0 taken 28272 times.
✓ Branch 1 taken 1020148 times.
1048420 for(y=0; y<framebuf->h;)
3613 {
3614 1020148 start = &(scrollbuf_old->line[y][256]);
3615
3616
4/4
✓ Branch 0 taken 1006012 times.
✓ Branch 1 taken 6347064 times.
✓ Branch 2 taken 6332928 times.
✓ Branch 3 taken 1020148 times.
7353076 for(dy=0; dy<ystep && dy+y<framebuf->h; dy++)
3617 {
3618 6332928 si = start;
3619 6332928 di = &(framebuf->line[y+dy][0]);
3620 6332928 i = xstep;
3621 6332928 firstx = 1;
3622
3623
2/2
✓ Branch 0 taken 1621229568 times.
✓ Branch 1 taken 6332928 times.
1627562496 for(dx=0; dx<framebuf->w; dx++)
3624 {
3625 1621229568 *(di++) = *si;
3626
3627
2/2
✓ Branch 0 taken 1366065344 times.
✓ Branch 1 taken 255164224 times.
1621229568 if(++i >= fuzz)
3628 {
3629
2/2
✓ Branch 0 taken 248831296 times.
✓ Branch 1 taken 6332928 times.
255164224 if(!firstx)
3630 248831296 si += fuzz;
3631 else
3632 {
3633 6332928 si += fuzz-xstep;
3634 6332928 firstx = 0;
3635 }
3636
3637 255164224 i = 0;
3638 255164224 }
3639 1621229568 }
3640 6332928 }
3641
3642
2/2
✓ Branch 0 taken 991876 times.
✓ Branch 1 taken 28272 times.
1020148 if(!firsty)
3643 991876 y += fuzz;
3644 else
3645 {
3646 28272 y += ystep;
3647 28272 ystep = fuzz;
3648 28272 firsty = 0;
3649 }
3650 }
3651 28272 }
3652
3653 18521188 void updatescr(bool allowwavy)
3654 {
3655
4/6
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 18520875 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 313 times.
✓ Branch 4 taken 313 times.
✗ Branch 5 not taken.
18521188 static BITMAP *wavybuf = create_bitmap_ex(8, framebuf->w, framebuf->h);
3656
4/6
✓ Branch 0 taken 313 times.
✓ Branch 1 taken 18520875 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 313 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 313 times.
18521188 static BITMAP *panorama = create_bitmap_ex(8, framebuf->w, framebuf->h);
3657 18521188 update_bmp_size(&wavybuf, framebuf->w, framebuf->h);
3658 18521188 update_bmp_size(&panorama, framebuf->w, framebuf->h);
3659
3660
2/2
✓ Branch 0 taken 18493087 times.
✓ Branch 1 taken 28101 times.
18521188 if(walk_through_walls)
3661 {
3662 28101 textout_ex(framebuf,font,"no walls",8,216,1,-1);
3663 28101 }
3664
3665
1/2
✓ Branch 0 taken 18521188 times.
✗ Branch 1 not taken.
18521188 if(Showpal)
3666 dump_pal(framebuf);
3667
3668
2/2
✓ Branch 0 taken 18005506 times.
✓ Branch 1 taken 515682 times.
18521188 if(!Playing)
3669 515682 black_opening_count=0;
3670
3671
2/2
✓ Branch 0 taken 18352343 times.
✓ Branch 1 taken 168845 times.
18521188 if(black_opening_count<0) //shape is opening up
3672 {
3673 168845 black_opening(framebuf,black_opening_x,black_opening_y,(66+black_opening_count),66);
3674
3675
2/4
✓ Branch 0 taken 168845 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 168845 times.
168845 if(Advance||(!Paused))
3676 {
3677 168845 ++black_opening_count;
3678 168845 }
3679 168845 }
3680
2/2
✓ Branch 0 taken 18303569 times.
✓ Branch 1 taken 48774 times.
18352343 else if(black_opening_count>0) //shape is closing
3681 {
3682 48774 black_opening(framebuf,black_opening_x,black_opening_y,black_opening_count,66);
3683
3684
2/4
✓ Branch 0 taken 48774 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 48774 times.
48774 if(Advance||(!Paused))
3685 {
3686 48774 --black_opening_count;
3687 48774 }
3688 48774 }
3689
3690
3/4
✓ Branch 0 taken 18306866 times.
✓ Branch 1 taken 214322 times.
✓ Branch 2 taken 18306866 times.
✗ Branch 3 not taken.
18521188 if(black_opening_count==0&&black_opening_shape==bosFADEBLACK)
3691 {
3692 black_opening_shape = bosCIRCLE;
3693 memcpy(RAMpal, tempblackpal, PAL_SIZE*sizeof(RGB));
3694 refreshTints();
3695 refreshpal=true;
3696 }
3697
3698
2/2
✓ Branch 0 taken 17888204 times.
✓ Branch 1 taken 632984 times.
18521188 if(refreshpal)
3699 {
3700 632984 refreshpal=false;
3701 632984 RAMpal[253] = _RGB(0,0,0);
3702 632984 RAMpal[254] = _RGB(255,255,255);
3703 632984 hw_palette = &RAMpal;
3704 632984 update_hw_pal = true;
3705 632984 refresh_rgb_tables();
3706 632984 }
3707
3708 18521188 bool clearwavy = (wavy <= 0);
3709
3710
2/2
✓ Branch 0 taken 8572 times.
✓ Branch 1 taken 18512616 times.
18521188 if(wavy <= 0)
3711 {
3712 // So far one thing can alter wavy apart from scripts: Wavy DMaps.
3713 18512616 wavy = (DMaps[cur_dmap].flags&dmfWAVY ? 4 : 0);
3714 18512616 }
3715
3716 18521188 blit(framebuf, wavybuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3717
3718
6/6
✓ Branch 0 taken 32278 times.
✓ Branch 1 taken 18488910 times.
✓ Branch 2 taken 32156 times.
✓ Branch 3 taken 122 times.
✓ Branch 4 taken 128 times.
✓ Branch 5 taken 32028 times.
18521188 if(wavy && Playing && allowwavy)
3719 {
3720 32028 draw_wavy(framebuf, wavybuf, wavy,false);
3721 32028 }
3722
3723
2/2
✓ Branch 0 taken 18512616 times.
✓ Branch 1 taken 8572 times.
18521188 if(clearwavy)
3724 18512616 wavy = 0; // Wavy was set by a DMap flag. Clear it.
3725
2/4
✓ Branch 0 taken 8572 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 8572 times.
8572 else if(Playing && !Paused)
3726 8572 wavy--; // Wavy was set by a script. Decrement it.
3727
3728
3/4
✓ Branch 0 taken 18005506 times.
✓ Branch 1 taken 515682 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18005506 times.
18521188 if(Playing && !Paused)
3729 18005506 ++light_wave_clk;
3730
3731
6/6
✓ Branch 0 taken 18005506 times.
✓ Branch 1 taken 515682 times.
✓ Branch 2 taken 260252 times.
✓ Branch 3 taken 17745254 times.
✓ Branch 4 taken 18 times.
✓ Branch 5 taken 260234 times.
18521188 if(Playing && msg_active && !screenscrolling)
3732 {
3733
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_bg_display_buf->clip))
3734 260167 blit_msgstr_bg(framebuf,0,0,0,playing_field_offset,256,176);
3735
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_portrait_display_buf->clip))
3736 260167 blit_msgstr_prt(framebuf,0,0,0,playing_field_offset,256,176);
3737
2/2
✓ Branch 0 taken 67 times.
✓ Branch 1 taken 260167 times.
260234 if(!(msg_txt_display_buf->clip))
3738 260167 blit_msgstr_fg(framebuf,0,0,0,playing_field_offset,256,176);
3739 260234 }
3740
3741
3/4
✓ Branch 0 taken 18521188 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 18327463 times.
✓ Branch 3 taken 193725 times.
18521188 bool nosubscr = GameLoaded && no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET);
3742
3743
2/2
✓ Branch 0 taken 18332736 times.
✓ Branch 1 taken 188452 times.
18521188 if(nosubscr)
3744 {
3745 188452 clear_to_color(panorama, 0);
3746 188452 blit(wavybuf,panorama,0,playing_field_offset,0,playing_field_offset/2,256,framebuf->h-playing_field_offset);
3747 188452 }
3748
3749 //TODO: Optimize blit 'overcalls' -Gleeok
3750
2/2
✓ Branch 0 taken 188452 times.
✓ Branch 1 taken 18332736 times.
18521188 BITMAP *source = nosubscr ? panorama : wavybuf;
3751 18521188 blit(source, framebuf, 0, 0, 0, 0, framebuf->w, framebuf->h);
3752
3753 18521188 update_hw_screen();
3754 18521188 }
3755
3756 //----------------------------------------------------------------
3757
3758 static PALETTE syspal;
3759 int32_t onGUISnapshot()
3760 {
3761 char buf[200];
3762 int32_t num=0;
3763 do
3764 {
3765 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3766 }
3767 while(num<99999 && exists(buf));
3768
3769 if (!al_save_bitmap(buf, al_get_backbuffer(all_get_display())))
3770 InfoDialog("Error", "Failed to save snapshot").show();
3771
3772 return D_O_K;
3773 }
3774
3775 int32_t onNonGUISnapshot()
3776 {
3777 PALETTE temppal;
3778 get_palette(temppal);
3779 bool realpal=(zc_getkey(KEY_ZC_LCONTROL, true) || zc_getkey(KEY_ZC_RCONTROL, true));
3780
3781 char buf[200];
3782 int32_t num=0;
3783
3784 do
3785 {
3786 sprintf(buf, "%szc_screen%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
3787 }
3788 while(num<99999 && exists(buf));
3789
3790 if (no_subscreen() && !(hero_scr->flags3&fNOSUBSCROFFSET) && !key[KEY_ALT])
3791 {
3792 BITMAP *b = create_bitmap_ex(8, 256, viewport.visible_height(show_bottom_8px));
3793 clear_to_color(b,0);
3794 blit(framebuf,b,0,playing_field_offset/2,0,0,b->w,b->h);
3795 alleg4_save_bitmap(b, SnapshotScale, buf, realpal ? temppal : RAMpal);
3796 destroy_bitmap(b);
3797 }
3798 else
3799 {
3800 alleg4_save_bitmap(framebuf, SnapshotScale, buf, realpal?temppal:RAMpal);
3801 }
3802
3803 return D_O_K;
3804 }
3805
3806 int32_t onSnapshot()
3807 {
3808 if(zc_getkey(KEY_LSHIFT, true)||zc_getkey(KEY_RSHIFT, true))
3809 {
3810 onGUISnapshot();
3811 }
3812 else
3813 {
3814 onNonGUISnapshot();
3815 }
3816
3817 return D_O_K;
3818 }
3819
3820 int32_t onSaveMapPic()
3821 {
3822 char buf[200];
3823 int32_t num=0;
3824 BITMAP* _screen_draw_buffer = NULL;
3825 _screen_draw_buffer = create_bitmap_ex(8,256,176);
3826
3827 do
3828 {
3829 sprintf(buf, "%szc_screen%05d.png", get_snap_str(), ++num);
3830 }
3831 while(num<99999 && exists(buf));
3832
3833 BITMAP* mappic = create_bitmap_ex(8,(256*16),(176*8));
3834 clear_to_color(mappic, BLACK);
3835
3836 if(!mappic)
3837 {
3838 enter_sys_pal();
3839 jwin_alert("View Map","Not enough memory.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
3840 exit_sys_pal();
3841 return D_O_K;;
3842 }
3843
3844 clear_to_color(_screen_draw_buffer, BLACK);
3845
3846 auto prev_viewport = viewport;
3847 viewport.x = 0;
3848 viewport.y = 0;
3849
3850 // draw the map
3851
3852 for(int32_t y=0; y<8; y++)
3853 {
3854 for(int32_t x=0; x<16; x++)
3855 {
3856 if (!displayOnMap(x, y))
3857 continue;
3858
3859 int screen = map_scr_xy_to_index(x, y);
3860 auto scrs = loadscr2(screen);
3861 mapscr* scr = &scrs[0];
3862 if (!scr->is_valid())
3863 continue;
3864
3865 screen_handles_t screen_handles;
3866 for (int i = 0; i <= 6; i++)
3867 screen_handles[i] = {scr, scrs[i].is_valid() ? &scrs[i] : nullptr, screen, i};
3868
3869 int xx = 0;
3870 int yy = -playing_field_offset;
3871
3872 if(XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3873 {
3874 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3875 do_ffc_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3876 }
3877
3878 if(XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3879 {
3880 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3881 do_ffc_layer(_screen_draw_buffer, -3, screen_handles[0], xx, yy);
3882 }
3883
3884 if(lenscheck(scr,0))
3885 putscr(scr, _screen_draw_buffer, 0, 0);
3886 do_ffc_layer(_screen_draw_buffer, 0, screen_handles[0], xx, yy);
3887 do_layer(_screen_draw_buffer, 0, screen_handles[1], xx, yy);
3888 do_ffc_layer(_screen_draw_buffer, 1, screen_handles[0], xx, yy);
3889
3890 if(!XOR(scr->flags7&fLAYER2BG, DMaps[cur_dmap].flags&dmfLAYER2BG))
3891 {
3892 do_layer(_screen_draw_buffer, 0, screen_handles[2], xx, yy);
3893 do_ffc_layer(_screen_draw_buffer, 2, screen_handles[0], xx, yy);
3894 }
3895
3896 putscrdoors(scr, _screen_draw_buffer, xx, yy);
3897 if(get_qr(qr_PUSHBLOCK_SPRITE_LAYER))
3898 {
3899 do_layer(_screen_draw_buffer, -2, screen_handles[0], xx, yy);
3900 if(get_qr(qr_PUSHBLOCK_LAYER_1_2))
3901 {
3902 do_layer(_screen_draw_buffer, -2, screen_handles[1], xx, yy);
3903 do_layer(_screen_draw_buffer, -2, screen_handles[2], xx, yy);
3904 }
3905 }
3906
3907 if(!XOR(scr->flags7&fLAYER3BG, DMaps[cur_dmap].flags&dmfLAYER3BG))
3908 {
3909 do_layer(_screen_draw_buffer, 0, screen_handles[3], xx, yy);
3910 do_ffc_layer(_screen_draw_buffer, 3, screen_handles[0], xx, yy);
3911 }
3912
3913 do_layer(_screen_draw_buffer, 0, screen_handles[4], xx, yy);
3914 do_ffc_layer(_screen_draw_buffer, 4, screen_handles[0], xx, yy);
3915 do_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3916 if(get_qr(qr_OVERHEAD_COMBOS_L1_L2))
3917 {
3918 do_layer(_screen_draw_buffer, -1, screen_handles[1], xx, yy);
3919 do_layer(_screen_draw_buffer, -1, screen_handles[2], xx, yy);
3920 }
3921 do_layer(_screen_draw_buffer, 0, screen_handles[5], xx, yy);
3922 do_ffc_layer(_screen_draw_buffer, 5, screen_handles[0], xx, yy);
3923 if(replay_version_check(40))
3924 do_ffc_layer(_screen_draw_buffer, -1, screen_handles[0], xx, yy);
3925 do_layer(_screen_draw_buffer, 0, screen_handles[6], xx, yy);
3926 do_ffc_layer(_screen_draw_buffer, 6, screen_handles[0], xx, yy);
3927 do_ffc_layer(_screen_draw_buffer, 7, screen_handles[0], xx, yy);
3928
3929 blit(_screen_draw_buffer, mappic, 0, 0, x*256, y*176, 256, 176);
3930 }
3931 }
3932
3933 viewport = prev_viewport;
3934 save_bitmap(buf,mappic,RAMpal);
3935 destroy_bitmap(mappic);
3936 destroy_bitmap(_screen_draw_buffer);
3937 return D_O_K;
3938 }
3939
3940 46 void f_Quit(int32_t type)
3941 {
3942
2/4
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 46 times.
✗ Branch 3 not taken.
46 if(type==qQUIT && !Playing)
3943 return;
3944
3945 46 bool from_menu = is_sys_pal;
3946
3947
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3948 {
3949 46 music_pause();
3950 46 pause_all_sfx();
3951 46 sys_mouse();
3952 46 }
3953 46 enter_sys_pal();
3954 46 clear_keybuf();
3955
3956
2/2
✓ Branch 0 taken 33 times.
✓ Branch 1 taken 13 times.
46 if (replay_version_check(0, 10))
3957 13 replay_poll();
3958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if (replay_is_replaying())
3959 46 replay_peek_quit();
3960
3961
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if (!replay_is_replaying())
3962 switch(type)
3963 {
3964 case qQUIT:
3965 onQuit();
3966 break;
3967
3968 case qRESET:
3969 onReset();
3970 break;
3971
3972 case qEXIT:
3973 onExit();
3974 break;
3975 }
3976
3977
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(Quit)
3978 {
3979 46 kill_sfx();
3980 46 music_stop();
3981 46 exit_sys_pal();
3982 46 update_hw_screen();
3983 46 }
3984 else
3985 {
3986 exit_sys_pal();
3987 if(!from_menu)
3988 {
3989 music_resume();
3990 resume_all_sfx();
3991 }
3992 }
3993
3994
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(!from_menu)
3995 46 game_mouse();
3996 46 eat_buttons();
3997
3998 46 zc_readrawkey(KEY_ESC);
3999
4000 46 zc_readrawkey(KEY_ENTER);
4001 46 }
4002
4003 //----------------------------------------------------------------
4004
4005 int32_t onNoWalls()
4006 {
4007 cheats_enqueue(Cheat::Walls);
4008 return D_O_K;
4009 }
4010
4011 int32_t onIgnoreSideview()
4012 {
4013 cheats_enqueue(Cheat::IgnoreSideView);
4014 return D_O_K;
4015 }
4016
4017 18519801 int32_t input_idle(bool checkmouse)
4018 {
4019 static int32_t mx, my, mz, mb;
4020
4021
4/6
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4960120 times.
✓ Branch 3 taken 13559681 times.
✗ Branch 4 not taken.
✓ Branch 5 taken 4960120 times.
23479921 if(keypressed() || zc_key_pressed() ||
4022
4/8
✓ Branch 0 taken 4960120 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4960120 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 4960120 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 4960120 times.
✗ Branch 7 not taken.
4960120 (checkmouse && (mx != mouse_x || my != mouse_y || mz != mouse_z || mb != mouse_b)))
4023 {
4024 13559681 idle_count = 0;
4025
4026
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13559681 times.
13559681 if(active_count < MAX_ACTIVE)
4027 {
4028 13559681 ++active_count;
4029 13559681 }
4030 13559681 }
4031
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4960120 times.
4960120 else if(idle_count < MAX_IDLE)
4032 {
4033 4960120 ++idle_count;
4034 4960120 active_count = 0;
4035 4960120 }
4036
4037 18519801 mx = mouse_x;
4038 18519801 my = mouse_y;
4039 18519801 mz = mouse_z;
4040 18519801 mb = mouse_b;
4041
4042 18519801 return idle_count;
4043 }
4044
4045 int32_t onGoFast()
4046 {
4047 cheats_enqueue(Cheat::Fast);
4048 return D_O_K;
4049 }
4050
4051 int32_t onKillCheat()
4052 {
4053 cheats_enqueue(Cheat::Kill);
4054 return D_O_K;
4055 }
4056
4057 int32_t onSecretsCheat()
4058 {
4059 cheats_enqueue(Cheat::TrigSecrets);
4060 return D_O_K;
4061 }
4062 int32_t onSecretsCheatPerm()
4063 {
4064 cheats_enqueue(Cheat::TrigSecretsPerm);
4065 return D_O_K;
4066 }
4067
4068 int32_t onShowLayer0()
4069 {
4070 show_layers[0] = !show_layers[0];
4071 return D_O_K;
4072 }
4073 int32_t onShowLayer1()
4074 {
4075 show_layers[1] = !show_layers[1];
4076 return D_O_K;
4077 }
4078 int32_t onShowLayer2()
4079 {
4080 show_layers[2] = !show_layers[2];
4081 return D_O_K;
4082 }
4083 int32_t onShowLayer3()
4084 {
4085 show_layers[3] = !show_layers[3];
4086 return D_O_K;
4087 }
4088 int32_t onShowLayer4()
4089 {
4090 show_layers[4] = !show_layers[4];
4091 return D_O_K;
4092 }
4093 int32_t onShowLayer5()
4094 {
4095 show_layers[5] = !show_layers[5];
4096 return D_O_K;
4097 }
4098 int32_t onShowLayer6()
4099 {
4100 show_layers[6] = !show_layers[6];
4101 return D_O_K;
4102 }
4103 int32_t onShowLayerO()
4104 {
4105 show_layer_over=!show_layer_over;
4106 return D_O_K;
4107 }
4108 int32_t onShowLayerP()
4109 {
4110 show_layer_push=!show_layer_push;
4111 return D_O_K;
4112 }
4113 int32_t onShowLayerS()
4114 {
4115 show_sprites=!show_sprites;
4116 return D_O_K;
4117 }
4118 int32_t onShowLayerF()
4119 {
4120 show_ffcs=!show_ffcs;
4121 return D_O_K;
4122 }
4123 int32_t onShowLayerW()
4124 {
4125 show_walkflags=!show_walkflags;
4126 if(show_walkflags)
4127 show_effectflags = false;
4128 return D_O_K;
4129 }
4130 int32_t onShowLayerE()
4131 {
4132 show_effectflags=!show_effectflags;
4133 if(show_effectflags)
4134 show_walkflags = false;
4135 return D_O_K;
4136 }
4137 int32_t onShowFFScripts()
4138 {
4139 show_ff_scripts=!show_ff_scripts;
4140 return D_O_K;
4141 }
4142 int32_t onShowHitboxes()
4143 {
4144 show_hitboxes=!show_hitboxes;
4145 return D_O_K;
4146 }
4147 int32_t onShowInfoOpacity()
4148 {
4149 info_opacity = vbound(getnumber("Debug Info Opacity",info_opacity),0,255);
4150 zc_set_config("zc","debug_info_opacity",info_opacity);
4151 return D_O_K;
4152 }
4153
4154 int32_t onLightSwitch()
4155 {
4156 cheats_enqueue(Cheat::Light);
4157 return D_O_K;
4158 }
4159
4160 int32_t onGoTo();
4161 int32_t onGoToComplete();
4162
4163 18519801 bool handle_close_btn_quit()
4164 {
4165
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(close_button_quit)
4166 {
4167 close_button_quit=false;
4168 f_Quit(qEXIT);
4169 }
4170 18519801 return (exiting_program = Quit==qEXIT);
4171 }
4172
4173 18519801 void syskeys()
4174 {
4175 18519801 update_system_keys();
4176
4177 int32_t oldtitle_version;
4178
4179 18519801 poll_joystick();
4180
4181 18519801 handle_close_btn_quit();
4182
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(Quit == qEXIT) return;
4183
4184
2/10
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 18519801 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
18519801 if(rMbtn() || (gui_mouse_b() && !mouse_down && ClickToFreeze &&!disableClickToFreeze))
4185 {
4186 System();
4187 }
4188
4189 18519801 mouse_down=gui_mouse_b();
4190
4191
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F1))
4192 {
4193 if(zc_get_system_key(KEY_ZC_LCONTROL) || zc_get_system_key(KEY_ZC_RCONTROL))
4194 {
4195 halt=!halt;
4196 //zinit.subscreen=(zinit.subscreen+1)%ssdtMAX;
4197 }
4198 else
4199 {
4200 Throttlefps=!Throttlefps;
4201 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4202 }
4203 }
4204
4205
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F2))
4206 {
4207 ShowFPS=!ShowFPS;
4208 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
4209 }
4210
4211
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18519801 if(zc_read_system_key(KEY_F3) && Playing) Paused=!Paused;
4212
4213
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18519801 if(zc_read_system_key(KEY_F4) && Playing)
4214 {
4215 Paused=true;
4216 Advance=true;
4217 }
4218
4219
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F6)) onTryQuit();
4220
4221 #ifndef ALLEGRO_MACOSX
4222
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F9)) f_Quit(qRESET);
4223
4224
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(zc_read_system_key(KEY_F10)) f_Quit(qEXIT);
4225 #else
4226 if(zc_read_system_key(KEY_F7)) f_Quit(qRESET);
4227
4228 if(zc_read_system_key(KEY_F8)) f_Quit(qEXIT);
4229 #endif
4230
1/8
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
18519801 if(zc_read_system_key(KEY_F5)&&(Playing && cur_screen<128 && DMaps[cur_dmap].flags&dmfVIEWMAP)) onSaveMapPic();
4231
4232
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if (zc_read_system_key(KEY_F12))
4233 {
4234 onSnapshot();
4235 }
4236
4237
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
18519801 if(debug_enabled && zc_read_system_key(KEY_TAB))
4238 set_debug(!get_debug());
4239
4240
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(CheatModifierKeys())
4241 {
4242 for(Cheat c = (Cheat)1; c < Cheat::Last; c = (Cheat)(c+1))
4243 {
4244 if(!bindable_cheat(c))
4245 continue;
4246 if(get_debug() || cheat >= cheat_lvl(c))
4247 {
4248 if(checkcheat(c))
4249 cheats_hit_bind(c);
4250 }
4251 }
4252 }
4253
4254
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(volkeys)
4255 {
4256 if(zc_read_system_key(KEY_PGUP)) master_volume(-1,midi_volume+8);
4257
4258 if(zc_read_system_key(KEY_PGDN)) master_volume(-1,midi_volume==255?248:midi_volume-8);
4259
4260 if(zc_read_system_key(KEY_HOME)) master_volume(digi_volume+8,-1);
4261
4262 if(zc_read_system_key(KEY_END)) master_volume(digi_volume==255?248:digi_volume-8,-1);
4263 }
4264
4265
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
18519801 if(!get_debug() || !SystemKeys || replay_is_replaying())
4266 18519801 goto bottom;
4267
4268 if(zc_readkey(KEY_P)) Paused=!Paused;
4269
4270 if(zc_readkey(KEY_A))
4271 {
4272 Paused=true;
4273 Advance=true;
4274 }
4275
4276 if(zc_readkey(KEY_G)) db=(db==999)?0:999;
4277 #ifndef ALLEGRO_MACOSX
4278 if(zc_readkey(KEY_F8)) Showpal=!Showpal;
4279
4280 if(zc_readkey(KEY_F7))
4281 {
4282 Matrix(ss_speed, ss_density, 0);
4283 game_pal();
4284 }
4285 #else
4286 // The reason these are different on Mac in the first place is that
4287 // the OS doesn't let us use F9 and F10...
4288 if(zc_readkey(KEY_F10)) Showpal=!Showpal;
4289
4290 if(zc_readkey(KEY_F9))
4291 {
4292 Matrix(ss_speed, ss_density, 0);
4293 game_pal();
4294 }
4295 #endif
4296 if(zc_readkey(KEY_PLUS_PAD) || zc_readkey(KEY_EQUALS))
4297 {
4298 //change containers
4299 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4300 {
4301 //magic containers
4302 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4303 {
4304 game->set_maxmagic(zc_min(game->get_maxmagic()+game->get_mp_per_block(),game->get_mp_per_block()*8));
4305 }
4306 else
4307 {
4308 game->set_maxlife(zc_min(game->get_maxlife()+game->get_hp_per_heart(),game->get_hp_per_heart()*24));
4309 }
4310 }
4311 else
4312 {
4313 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4314 {
4315 game->set_magic(zc_min(game->get_magic()+1,game->get_maxmagic()));
4316 }
4317 else
4318 {
4319 game->set_life(zc_min(game->get_life()+1,game->get_maxlife()));
4320 }
4321 }
4322 }
4323
4324 if(zc_readkey(KEY_MINUS_PAD) || zc_readkey(KEY_MINUS))
4325 {
4326 //change containers
4327 if(zc_getkey(KEY_ZC_LCONTROL) || zc_getkey(KEY_ZC_RCONTROL))
4328 {
4329 //magic containers
4330 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4331 {
4332 game->set_maxmagic(zc_max(game->get_maxmagic()-game->get_mp_per_block(),0));
4333 game->set_magic(zc_min(game->get_maxmagic(), game->get_magic()));
4334 //heart containers
4335 }
4336 else
4337 {
4338 game->set_maxlife(zc_max(game->get_maxlife()-game->get_hp_per_heart(),game->get_hp_per_heart()));
4339 game->set_life(zc_min(game->get_maxlife(), game->get_life()));
4340 }
4341 }
4342 else
4343 {
4344 if(zc_getkey(KEY_LSHIFT) || zc_getkey(KEY_RSHIFT))
4345 {
4346 game->set_magic(zc_max(game->get_magic()-1,0));
4347 }
4348 else
4349 {
4350 game->set_life(zc_max(game->get_life()-1,0));
4351 }
4352 }
4353 }
4354
4355 if(zc_readkey(KEY_COMMA)) jukebox(currmidi-1);
4356
4357 if(zc_readkey(KEY_STOP)) jukebox(currmidi+1);
4358
4359 verifyBothWeapons();
4360
4361 bottom:
4362
4363
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(input_idle(true) > after_time())
4364 {
4365 Matrix(ss_speed, ss_density, 0);
4366 game_pal();
4367 }
4368 18519801 }
4369
4370 9847122 void checkQuitKeys()
4371 {
4372 #ifndef ALLEGRO_MACOSX
4373
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9847122 times.
9847122 if(key[KEY_F9]) f_Quit(qRESET);
4374
4375
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 9847122 times.
9847122 if(key[KEY_F10]) f_Quit(qEXIT);
4376 #else
4377 if(key[KEY_F7]) f_Quit(qRESET);
4378
4379 if(key[KEY_F8]) f_Quit(qEXIT);
4380 #endif
4381 9847122 }
4382
4383 18520001 bool CheatModifierKeys()
4384 {
4385 // Cheats are replayed via the X cheat step, no need to check for keyboard input
4386 // to trigger cheats.
4387
2/2
✓ Branch 0 taken 18519701 times.
✓ Branch 1 taken 300 times.
18520001 if (replay_is_replaying())
4388 18519701 return false;
4389
4390
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 200 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
300 if ( ( cheat_modifier_keys[0] > 0 && key[cheat_modifier_keys[0]] ) ||
4391
2/2
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 100 times.
200 ( cheat_modifier_keys[1] > 0 && key[cheat_modifier_keys[1]] ) ||
4392
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 100 times.
100 (cheat_modifier_keys[0] <= 0 && cheat_modifier_keys[1] <= 0))
4393 {
4394
0/4
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
200 if ( ( cheat_modifier_keys[2] <= 0 || key[cheat_modifier_keys[2]] ) ||
4395 ( cheat_modifier_keys[3] > 0 && key[cheat_modifier_keys[3]] ) ||
4396 (cheat_modifier_keys[2] <= 0 && cheat_modifier_keys[3] <= 0))
4397 {
4398 return true;
4399 }
4400 }
4401 100 return false;
4402 18519801 }
4403
4404 //99:05:54, for some reason?
4405 #define OLDMAXTIME 21405240
4406 //9000:00:00, the highest even-thousand hour fitting within 32b signed. This is 375 *DAYS*.
4407 #define MAXTIME 1944000000
4408
4409 // (qr, value)
4410 414 static std::queue<std::pair<int, bool>> change_qr_queue;
4411
4412 7 void enqueue_qr_change(int qr, bool value)
4413 {
4414 7 change_qr_queue.push({qr, value});
4415 7 }
4416
4417 // During regular play, QR changes issued through `syskey` / `System` and enqueued
4418 // and soon executed here.
4419 // During playing back a replay file, the replay system adds to the same queue and
4420 // is executed here too.
4421 // This is currently only used to allow users to configure qr_HIDE_BOTTOM_8_PIXELS, but
4422 // could be later extended to all QRs (perhaps as a cheat).
4423 18520223 void process_enqueued_qr_changes()
4424 {
4425
2/2
✓ Branch 0 taken 101 times.
✓ Branch 1 taken 18520122 times.
18520223 if (replay_is_replaying())
4426 18520122 replay_do_qrs();
4427
4428
2/2
✓ Branch 0 taken 18520223 times.
✓ Branch 1 taken 7 times.
18520230 while (!change_qr_queue.empty())
4429 {
4430 28 auto [qr, value] = change_qr_queue.front();
4431 7 change_qr_queue.pop();
4432
4433 // Don't modify `quest_rules`, as that is used to store the canonical QR value which can be reset to
4434 // via system menus. Changing the unpacked array is enough to modify the engine's behavior.
4435 14 _qrs_unpacked[qr] = value;
4436 7 apply_qr_rule(qr);
4437
4438
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1 times.
7 if (replay_is_recording())
4439 2 replay_step_qr(qr, value);
4440 }
4441 18520223 }
4442
4443 18521188 void advanceframe(bool allowwavy, bool sfxcleanup, bool allowF6Script)
4444 {
4445
1/2
✓ Branch 0 taken 18521188 times.
✗ Branch 1 not taken.
18521188 if(zcmusic!=NULL)
4446 {
4447 zcmusic_poll();
4448 }
4449 18521188 zcmixer_update(zcmixer, emusic_volume, FFCore.usr_music_volume, get_qr(qr_OLD_SCRIPT_VOLUME));
4450
4451 18521188 updatescr(allowwavy);
4452
4453 18521188 Advance=false;
4454
2/6
✗ Branch 0 not taken.
✓ Branch 1 taken 18521188 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 18521188 times.
18521188 while(Paused && !Advance && !Quit)
4455 {
4456 // have to call this, otherwise we'll get an infinite loop
4457 syskeys();
4458 if(allowF6Script)
4459 {
4460 FFCore.runF6Engine();
4461 }
4462
4463 #ifdef _WIN32
4464
4465 if(use_dwm_flush)
4466 {
4467 do_DwmFlush();
4468 }
4469
4470 #endif
4471
4472 // to keep music playing
4473 if(zcmusic!=NULL)
4474 {
4475 zcmusic_poll();
4476 }
4477
4478 update_hw_screen();
4479 }
4480
4481
2/2
✓ Branch 0 taken 18519830 times.
✓ Branch 1 taken 1358 times.
18521188 if(Quit)
4482 1358 return;
4483
4484
3/4
✓ Branch 0 taken 18004460 times.
✓ Branch 1 taken 515370 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 18004460 times.
18519830 if(Playing && game->get_time()<unsigned(get_qr(qr_GREATER_MAX_TIME) ? MAXTIME : OLDMAXTIME))
4485 18004460 game->change_time(1);
4486
4487 // Many mistakes have been make re: inputs, and we are stuck with many replays relying on those mistakes.
4488
4489 18519830 bool should_reset_down_state = !get_qr(qr_BROKEN_INPUT_DOWN_STATE);
4490
2/2
✓ Branch 0 taken 8720218 times.
✓ Branch 1 taken 9799612 times.
18519830 if (replay_version_check(0, 16))
4491 9799612 should_reset_down_state = replay_version_check(11, 16);
4492
2/2
✓ Branch 0 taken 15093802 times.
✓ Branch 1 taken 3426028 times.
18519830 if (should_reset_down_state)
4493 {
4494
2/2
✓ Branch 0 taken 61668504 times.
✓ Branch 1 taken 3426028 times.
65094532 for (int i = 0; i < ZC_CONTROL_STATES; i++)
4495 61668504 down_control_states[i] = raw_control_state[i];
4496 3426028 }
4497
4498
2/2
✓ Branch 0 taken 29 times.
✓ Branch 1 taken 18519801 times.
18519830 if (replay_is_active())
4499 {
4500
2/2
✓ Branch 0 taken 1545428 times.
✓ Branch 1 taken 16974373 times.
18519801 if (replay_version_check(3))
4501 16974373 replay_poll();
4502
4503
4/4
✓ Branch 0 taken 7478911 times.
✓ Branch 1 taken 11040890 times.
✓ Branch 2 taken 100535 times.
✓ Branch 3 taken 7378376 times.
18519801 if (replay_version_check(11) || replay_version_check(6, 8))
4504 11141425 replay_peek_input();
4505 18519801 }
4506
4507 18519830 process_enqueued_qr_changes();
4508
4509 18519830 load_control_called_this_frame = false;
4510
4511 18519830 poll_keyboard();
4512 18519830 update_keys();
4513
4514 18519830 ++frame;
4515
4516
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18519701 times.
18519830 if (replay_is_replaying())
4517 18519701 replay_do_cheats();
4518 18519830 syskeys();
4519
4520 // The mouse variables can change from the mouse thread at anytime during a frame,
4521 // so save the result at the start so that replaying is consistent.
4522 18519830 script_mouse_x = gui_mouse_x();
4523 18519830 script_mouse_y = gui_mouse_y();
4524 18519830 script_mouse_z = mouse_z;
4525 18519830 script_mouse_b = mouse_b;
4526
4527 // Cheats used via the System menu (called by syskeys) will call cheats_enqueue. syskeys
4528 // is called just above, and in the paused loop above, so the queue-and-defer-slightly
4529 // approach here means it doesn't matter which call adds the cheat.
4530 18519830 cheats_execute_queued();
4531
4532
2/2
✓ Branch 0 taken 129 times.
✓ Branch 1 taken 18519701 times.
18519830 if (replay_is_replaying())
4533 18519701 replay_peek_quit();
4534
2/2
✓ Branch 0 taken 18519784 times.
✓ Branch 1 taken 46 times.
18519830 if (GameFlags & GAMEFLAG_TRYQUIT)
4535 46 replay_step_quit(0);
4536
2/2
✓ Branch 0 taken 3314 times.
✓ Branch 1 taken 18516516 times.
18519830 if(allowF6Script)
4537 18516516 FFCore.runF6Engine();
4538
2/2
✓ Branch 0 taken 755 times.
✓ Branch 1 taken 18519075 times.
18519830 if (Quit)
4539 755 replay_step_quit(Quit);
4540
4541 #ifdef _WIN32
4542
4543 if(use_dwm_flush)
4544 {
4545 do_DwmFlush();
4546 }
4547
4548 #endif
4549
4550
2/2
✓ Branch 0 taken 208637 times.
✓ Branch 1 taken 18311193 times.
18519830 if(sfxcleanup)
4551 18311193 sfx_cleanup();
4552
4553 18519830 frame_timings_poll();
4554
4555 #ifdef __EMSCRIPTEN__
4556 // Yield the main thread back to the browser occasionally.
4557 if (is_headless())
4558 {
4559 static int rate = 10000;
4560 static int force_yield = rate;
4561 if (force_yield++ >= rate)
4562 {
4563 force_yield = 0;
4564 emscripten_sleep(0);
4565 }
4566 }
4567 #endif
4568
4569
3/4
✓ Branch 0 taken 100 times.
✓ Branch 1 taken 18519730 times.
✓ Branch 2 taken 100 times.
✗ Branch 3 not taken.
18519830 if (zqtesting_mode && test_mode_auto_restart)
4570 {
4571 static auto last_write_time = fs::last_write_time(qstpath);
4572 static auto last_check = std::chrono::system_clock::now();
4573
4574 if (std::chrono::system_clock::now() - last_check > 200ms)
4575 {
4576 last_check = std::chrono::system_clock::now();
4577 auto write_time = fs::last_write_time(qstpath);
4578 if (last_write_time != write_time)
4579 {
4580 last_write_time = write_time;
4581 disableClickToFreeze = false;
4582 Quit = qRESET;
4583 replay_quit();
4584 }
4585 }
4586 }
4587 18521188 }
4588
4589 590 void zapout()
4590 {
4591 590 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4592 590 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4593
4594 590 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4595 590 script_drawing_commands.Clear();
4596
4597 // zap out
4598
2/2
✓ Branch 0 taken 590 times.
✓ Branch 1 taken 14160 times.
14750 for(int32_t i=1; i<=24; i++)
4599 {
4600 14160 draw_fuzzy(i);
4601 14160 advanceframe(true);
4602
4603
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14160 times.
14160 if(Quit)
4604 {
4605 break;
4606 }
4607 14160 }
4608 590 }
4609
4610 588 void zapin()
4611 {
4612 588 FFCore.warpScriptCheck();
4613 588 draw_screen();
4614 588 set_clip_rect(scrollbuf_old, 0, 0, scrollbuf_old->w, scrollbuf_old->h);
4615 588 blit(framebuf,scrollbuf_old,0,0,256,0,256,framebuf->h);
4616
4617 // zap out
4618 588 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4619
2/2
✓ Branch 0 taken 588 times.
✓ Branch 1 taken 14112 times.
14700 for(int32_t i=24; i>=1; i--)
4620 {
4621 14112 draw_fuzzy(i);
4622 14112 advanceframe(true);
4623
4624
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14112 times.
14112 if(Quit)
4625 {
4626 break;
4627 }
4628 14112 }
4629 588 }
4630
4631
4632 235 void wavyout(bool showhero)
4633 {
4634 235 draw_screen(showhero);
4635
4636 235 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4637 235 clear_to_color(wavebuf,0);
4638 235 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4639
4640 static PALETTE wavepal;
4641
4642 int32_t ofs;
4643 235 int32_t amplitude=8;
4644
4645 235 int32_t wavelength=4;
4646 235 int height = viewport.visible_height(show_bottom_8px);
4647 235 double palpos=0, palstep=4, palstop=126;
4648
4649 235 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4650
2/2
✓ Branch 0 taken 234 times.
✓ Branch 1 taken 9845 times.
10079 for(int32_t i=0; i<height; i+=wavelength)
4651 {
4652
2/2
✓ Branch 0 taken 2520320 times.
✓ Branch 1 taken 9845 times.
2530165 for(int32_t l=0; l<256; l++)
4653 {
4654 2520320 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4655 2520320 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4656 2520320 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4657 2520320 }
4658
4659 9845 palpos+=palstep;
4660
4661
1/2
✓ Branch 0 taken 9845 times.
✗ Branch 1 not taken.
9845 if(palpos>=0)
4662 {
4663 9845 hw_palette = &wavepal;
4664 9845 update_hw_pal = true;
4665 9845 }
4666 else
4667 {
4668 hw_palette = &RAMpal;
4669 update_hw_pal = true;
4670 }
4671
4672
2/2
✓ Branch 0 taken 1653960 times.
✓ Branch 1 taken 9845 times.
1663805 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4673 {
4674
2/2
✓ Branch 0 taken 423413760 times.
✓ Branch 1 taken 1653960 times.
425067720 for(int32_t k=0; k<256; k++)
4675 {
4676 423413760 ofs=0;
4677
4678
4/4
✓ Branch 0 taken 206448640 times.
✓ Branch 1 taken 216965120 times.
✓ Branch 2 taken 103224320 times.
✓ Branch 3 taken 103224320 times.
423413760 if((j<i)&&(j&1))
4679 {
4680 103224320 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4681 103224320 }
4682
4683 423413760 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4684 423413760 }
4685 1653960 }
4686
4687 9845 advanceframe(true);
4688
4689
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9844 times.
9845 if(Quit)
4690 1 break;
4691 9844 }
4692
4693 235 destroy_bitmap(wavebuf);
4694
4695 235 hw_palette = &RAMpal;
4696 235 update_hw_pal = true;
4697 235 }
4698
4699 232 void wavyin()
4700 {
4701 232 draw_screen();
4702
4703 232 BITMAP *wavebuf = create_bitmap_ex(8,288,framebuf->h);
4704 232 clear_to_color(wavebuf,0);
4705 232 blit(framebuf,wavebuf,0,0,16,0,framebuf->w,framebuf->h);
4706
4707 static PALETTE wavepal;
4708
4709 232 refreshpal=false;
4710 int32_t ofs;
4711 232 int32_t amplitude=8;
4712 232 int32_t wavelength=4;
4713 232 int height = viewport.visible_height(show_bottom_8px);
4714 232 double palpos=height, palstep=4, palstop=126;
4715
4716 232 FFCore.runGenericPassiveEngine(SCR_TIMING_END_FRAME);
4717
2/2
✓ Branch 0 taken 231 times.
✓ Branch 1 taken 9703 times.
9934 for(int32_t i=0; i<height; i+=wavelength)
4718 {
4719
2/2
✓ Branch 0 taken 2483968 times.
✓ Branch 1 taken 9703 times.
2493671 for(int32_t l=0; l<256; l++)
4720 {
4721 2483968 wavepal[l].r=vbound(int32_t(RAMpal[l].r+((palpos/palstop)*(255-RAMpal[l].r))),0,255);
4722 2483968 wavepal[l].g=vbound(int32_t(RAMpal[l].g+((palpos/palstop)*(255-RAMpal[l].g))),0,255);
4723 2483968 wavepal[l].b=vbound(int32_t(RAMpal[l].b+((palpos/palstop)*(255-RAMpal[l].b))),0,255);
4724 2483968 }
4725
4726 9703 palpos-=palstep;
4727
4728
1/2
✓ Branch 0 taken 9703 times.
✗ Branch 1 not taken.
9703 if(palpos>=0)
4729 {
4730 9703 hw_palette = &wavepal;
4731 9703 update_hw_pal = true;
4732 9703 }
4733 else
4734 {
4735 hw_palette = &RAMpal;
4736 update_hw_pal = true;
4737 }
4738
4739
2/2
✓ Branch 0 taken 1630104 times.
✓ Branch 1 taken 9703 times.
1639807 for(int32_t j=0; j+playing_field_offset<framebuf->h; j++)
4740 {
4741
2/2
✓ Branch 0 taken 417306624 times.
✓ Branch 1 taken 1630104 times.
418936728 for(int32_t k=0; k<256; k++)
4742 {
4743 417306624 ofs=0;
4744
4745
4/4
✓ Branch 0 taken 211158272 times.
✓ Branch 1 taken 206148352 times.
✓ Branch 2 taken 106821120 times.
✓ Branch 3 taken 104337152 times.
417306624 if((j<(height-1-i))&&(j&1))
4746 {
4747 104337152 ofs=int32_t(zc::math::Sin((double(i+j)*2*PI/height))*amplitude);
4748 104337152 }
4749
4750 417306624 framebuf->line[j+playing_field_offset][k]=wavebuf->line[j+playing_field_offset][k+ofs+16];
4751 417306624 }
4752 1630104 }
4753
4754 9703 advanceframe(true);
4755
4756
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 9702 times.
9703 if(Quit)
4757 1 break;
4758 9702 }
4759
4760 232 destroy_bitmap(wavebuf);
4761
4762 232 hw_palette = &RAMpal;
4763 232 update_hw_pal = true;
4764 232 }
4765
4766 4346 void blackscr(int32_t fcnt,bool showsubscr)
4767 {
4768 4346 reset_pal_cycling();
4769 4346 script_drawing_commands.Clear();
4770
4771 4346 FFCore.warpScriptCheck();
4772 4346 bool showtime = game->should_show_time();
4773
2/2
✓ Branch 0 taken 4339 times.
✓ Branch 1 taken 129937 times.
134276 while(fcnt>0)
4774 {
4775 129937 clear_bitmap(framebuf);
4776
4777
2/2
✓ Branch 0 taken 59310 times.
✓ Branch 1 taken 70627 times.
129937 if(showsubscr)
4778 {
4779 70627 put_passive_subscr(framebuf,0,0,showtime,sspUP);
4780
3/4
✓ Branch 0 taken 70627 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1410 times.
✓ Branch 3 taken 69217 times.
70627 if(get_qr(qr_SCRIPTDRAWSINWARPS) || (get_qr(qr_PASSIVE_SUBSCRIPT_RUNS_WHEN_GAME_IS_FROZEN)))
4781 {
4782 1410 do_script_draws(framebuf, origin_scr, 0, playing_field_offset);
4783 1410 }
4784 70627 }
4785
4786 129937 advanceframe(true);
4787
4788
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 129930 times.
129937 if(Quit)
4789 7 break;
4790
4791 129930 --fcnt;
4792 }
4793 4346 }
4794
4795 2738 void openscreen(int32_t shape)
4796 {
4797 2738 update_viewport();
4798 2738 is_opening_screen = true;
4799 2738 reset_pal_cycling();
4800 2738 black_opening_count=0;
4801
4802
3/4
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 2207 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 531 times.
2738 if(COOLSCROLL || shape>-1)
4803 {
4804 2207 open_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4805 2207 return;
4806 }
4807 else
4808 {
4809 531 Hero.setDontDraw(true);
4810 531 show_subscreen_dmap_dots=false;
4811 531 show_subscreen_numbers=false;
4812 531 show_subscreen_life=false;
4813 }
4814
4815 531 int32_t x=128;
4816
4817 531 FFCore.warpScriptCheck();
4818
2/2
✓ Branch 0 taken 531 times.
✓ Branch 1 taken 42480 times.
43011 for(int32_t i=0; i<80; i++)
4819 {
4820 42480 draw_screen();
4821 42480 x=128-(((i*128/80)/8)*8);
4822
4823
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(x>0)
4824 {
4825 42480 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4826 42480 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4827 42480 }
4828
4829 42480 advanceframe(true);
4830
4831
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42480 times.
42480 if(Quit)
4832 {
4833 break;
4834 }
4835 42480 }
4836
4837 531 Hero.setDontDraw(false);
4838 531 show_subscreen_items=true;
4839 531 show_subscreen_dmap_dots=true;
4840 531 show_subscreen_numbers=true;
4841 531 show_subscreen_life=true;
4842 2738 }
4843
4844 14 void closescreen(int32_t shape)
4845 {
4846 14 is_opening_screen = false;
4847 14 reset_pal_cycling();
4848 14 black_opening_count=0;
4849
4850
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
14 if(COOLSCROLL || shape>-1)
4851 {
4852 14 close_black_opening(HeroX()+8, (HeroY()-HeroZ()-HeroFakeZ())+8+playing_field_offset, true, shape);
4853 14 return;
4854 }
4855 else
4856 {
4857 Hero.setDontDraw(true);
4858 show_subscreen_dmap_dots=false;
4859 show_subscreen_numbers=false;
4860 // show_subscreen_items=false;
4861 show_subscreen_life=false;
4862 }
4863
4864 int32_t x=128;
4865
4866 FFCore.warpScriptCheck();
4867 for(int32_t i=79; i>=0; --i)
4868 {
4869 draw_screen();
4870 x=128-(((i*128/80)/8)*8);
4871
4872 if(x>0)
4873 {
4874 rectfill(framebuf,0,playing_field_offset,x,(viewport.h - 1)+playing_field_offset,0);
4875 rectfill(framebuf,viewport.w-x,playing_field_offset,255,(viewport.h - 1)+playing_field_offset,0);
4876 }
4877
4878 advanceframe(true);
4879
4880 if(Quit)
4881 {
4882 break;
4883 }
4884 }
4885
4886 Hero.setDontDraw(false);
4887 show_subscreen_items=true;
4888 show_subscreen_dmap_dots=true;
4889 14 }
4890
4891 324 int32_t TriforceCount()
4892 {
4893 324 int32_t c=0;
4894
4895
2/2
✓ Branch 0 taken 2592 times.
✓ Branch 1 taken 324 times.
2916 for(int32_t i=1; i<=8; i++)
4896
2/2
✓ Branch 0 taken 484 times.
✓ Branch 1 taken 2108 times.
4700 if(game->lvlitems[i]&(1 << li_mcguffin))
4897 2108 ++c;
4898
4899 324 return c;
4900 }
4901
4902 int32_t onCustomGame()
4903 {
4904 auto save = get_unset_save_slot();
4905 if (!save)
4906 return D_CLOSE;
4907
4908 if (prompt_for_quest_path(save->header->qstpath))
4909 {
4910 save->header->qstpath = qstpath;
4911 return D_O_K;
4912 }
4913
4914 return D_CLOSE;
4915 }
4916
4917 int32_t onContinue()
4918 {
4919 return D_CLOSE;
4920 }
4921
4922 int32_t onThrottleFPS()
4923 {
4924 Throttlefps = !Throttlefps;
4925 zc_set_config(cfg_sect,"throttlefps", (int32_t)Throttlefps);
4926 return D_O_K;
4927 }
4928
4929 int32_t onWinPosSave()
4930 {
4931 SaveWinPos = !SaveWinPos;
4932 zc_set_config(cfg_sect,"save_window_position",(int32_t)SaveWinPos);
4933 return D_O_K;
4934 }
4935 int32_t onIntegerScaling()
4936 {
4937 scaleForceInteger = !scaleForceInteger;
4938 zc_set_config("zeldadx","scaling_force_integer",(int)scaleForceInteger);
4939 return D_O_K;
4940 }
4941 int32_t onStretchGame()
4942 {
4943 stretchGame = !stretchGame;
4944 zc_set_config("zeldadx","stretch_game_area",stretchGame?1:0);
4945 return D_O_K;
4946 }
4947
4948 int32_t onClickToFreeze()
4949 {
4950 ClickToFreeze = !ClickToFreeze;
4951 zc_set_config(cfg_sect,"clicktofreeze", (int32_t)ClickToFreeze);
4952 return D_O_K;
4953 }
4954
4955 int32_t OnSaveZCConfig()
4956 {
4957 if(jwin_alert3(
4958 "Save Configuration",
4959 "Are you sure that you wish to save your present configuration settings?",
4960 "This will overwrite your prior settings!",
4961 NULL,
4962 "&Yes",
4963 "&No",
4964 NULL,
4965 'y',
4966 'n',
4967 0,
4968 get_zc_font(font_lfont)) == 1)
4969 {
4970 save_game_configs();
4971 return D_O_K;
4972 }
4973 else return D_O_K;
4974 }
4975
4976 int32_t OnnClearQuestDir()
4977 {
4978 auto current_path = fs::current_path() / "quests";
4979 if(jwin_alert3(
4980 "Clear Current Directory Cache",
4981 "Are you sure that you wish to reset where ZC Player looks for quests?",
4982 fmt::format("The new directory will be: {}", current_path.string()).c_str(),
4983 NULL,
4984 "&Yes",
4985 "&No",
4986 NULL,
4987 'y',
4988 'n',
4989 0,
4990 get_zc_font(font_lfont)) == 1)
4991 {
4992 zc_set_config("zeldadx","quest_dir","quests");
4993 flush_config_file();
4994 strcpy(qstdir,"quests");
4995 #ifdef __EMSCRIPTEN__
4996 em_sync_fs();
4997 #endif
4998 return D_O_K;
4999 }
5000 else return D_O_K;
5001 }
5002
5003 int32_t onConsole()
5004 {
5005 if ( !console_enabled )
5006 {
5007 AlertDialog("ZC Console",
5008 "Open the ZC Console?"
5009 "\nThis will display any messages logged by scripts,"
5010 " including errors.",
5011 [&](bool ret,bool)
5012 {
5013 if(ret)
5014 {
5015 FFCore.ZScriptConsole(true);
5016 }
5017 }).show();
5018 return D_O_K;
5019 }
5020 else
5021 {
5022 FFCore.ZScriptConsole(false);
5023 return D_O_K;
5024 }
5025 }
5026
5027 int32_t onClrConsoleOnReload()
5028 {
5029 clearConsoleOnReload = !clearConsoleOnReload;
5030 zc_set_config("CONSOLE","clear_console_on_reload",clearConsoleOnReload?1:0);
5031 return D_O_K;
5032 }
5033 int32_t onClrConsoleOnLoad()
5034 {
5035 clearConsoleOnLoad = !clearConsoleOnLoad;
5036 zc_set_config("CONSOLE","clear_console_on_load",clearConsoleOnLoad?1:0);
5037 return D_O_K;
5038 }
5039
5040
5041 int32_t onFrameSkip()
5042 {
5043 FrameSkip = !FrameSkip;
5044 return D_O_K;
5045 }
5046
5047 int32_t onSaveDragResize()
5048 {
5049 SaveDragResize = !SaveDragResize;
5050 zc_set_config(cfg_sect,"save_drag_resize",(int32_t)SaveDragResize);
5051 return D_O_K;
5052 }
5053
5054 int32_t onDragAspect()
5055 {
5056 DragAspect = !DragAspect;
5057 zc_set_config(cfg_sect,"drag_aspect",(int32_t)DragAspect);
5058 return D_O_K;
5059 }
5060
5061 int32_t onTransLayers()
5062 {
5063 TransLayers = !TransLayers;
5064 zc_set_config(cfg_sect,"translayers",(int32_t)TransLayers);
5065 return D_O_K;
5066 }
5067
5068 int32_t onNESquit()
5069 {
5070 NESquit = !NESquit;
5071 zc_set_config(cfg_sect,"fastquit",(int32_t)NESquit);
5072 return D_O_K;
5073 }
5074
5075 int32_t onVolKeys()
5076 {
5077 volkeys = !volkeys;
5078 zc_set_config(sfx_sect,"volkeys",(int32_t)volkeys);
5079 return D_O_K;
5080 }
5081
5082 int32_t onShowFPS()
5083 {
5084 ShowFPS = !ShowFPS;
5085 zc_set_config(cfg_sect,"showfps",(int32_t)ShowFPS);
5086 return D_O_K;
5087 }
5088
5089 int32_t onShowTime()
5090 {
5091 ShowGameTime = !ShowGameTime;
5092 zc_set_config(cfg_sect,"showtime",ShowGameTime);
5093 return D_O_K;
5094 }
5095
5096 2185336518 bool is_Fkey(int32_t k)
5097 {
5098
2/2
✓ Branch 0 taken 222237612 times.
✓ Branch 1 taken 1963098906 times.
2185336518 switch(k)
5099 {
5100 case KEY_F1:
5101 case KEY_F2:
5102 case KEY_F3:
5103 case KEY_F4:
5104 case KEY_F5:
5105 case KEY_F6:
5106 case KEY_F7:
5107 case KEY_F8:
5108 case KEY_F9:
5109 case KEY_F10:
5110 case KEY_F11:
5111 case KEY_F12:
5112 222237612 return true;
5113 }
5114
5115 1963098906 return false;
5116 2185336518 }
5117
5118 void kb_getkey(DIALOG *d);
5119
5120 //Used by all keyboard key settings dialogues.
5121 void kb_clearjoystick(DIALOG *d)
5122 {
5123 d->flags|=D_SELECTED;
5124
5125 jwin_button_proc(MSG_DRAW,d,0);
5126 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5127 // text_mode(vc(11));
5128 textout_centre_ex(screen, font, "Press any key to clear", gui_bmp->w/2, gui_bmp->h/2 - 8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5129 textout_centre_ex(screen, font, "ESC to cancel", gui_bmp->w/2, gui_bmp->h/2, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5130
5131 update_hw_screen();
5132
5133 clear_keybuf();
5134 int32_t k = next_press_key();
5135 clear_keybuf();
5136
5137 //shnarf
5138 //47=f1
5139 //59=esc
5140 // if(k>0 && k<123 && !((k>46)&&(k<60)))
5141 // *((int32_t*)d->dp3) = k;
5142 if ( k != 59 ) *((int32_t*)d->dp3) = 0;
5143
5144
5145 d->flags&=~D_SELECTED;
5146 }
5147
5148 //Clears key to 0.
5149 //Used by all keyboard key settings dialogues.
5150 void kb_clearkey(DIALOG *d);
5151
5152 int32_t d_j_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5153 {
5154 switch(msg)
5155 {
5156 case MSG_KEY:
5157 case MSG_CLICK:
5158
5159 kb_clearjoystick(d);
5160
5161 while(gui_mouse_b())
5162 {
5163 clear_keybuf();
5164 rest(1);
5165 }
5166
5167 return D_REDRAW;
5168 }
5169
5170 return jwin_button_proc(msg,d,c);
5171 }
5172
5173 int32_t d_kbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5174 //Only used in keyboard settings dialogues to clear keys.
5175 int32_t d_k_clearbutton_proc(int32_t msg,DIALOG *d,int32_t c);
5176
5177 int32_t j_getbtn(DIALOG *d)
5178 {
5179 d->flags|=D_SELECTED;
5180 jwin_button_proc(MSG_DRAW,d,0);
5181 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5182 // text_mode(vc(11));
5183 int32_t y = screen->h/2 - 12;
5184 textout_centre_ex(screen, font, "Press a button", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5185 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5186 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5187
5188 update_hw_screen();
5189
5190 int32_t b = next_joy_input(true);
5191 if (b == -2)
5192 return D_CLOSE;
5193
5194 if(b>=0)
5195 *((int32_t*)d->dp3) = b;
5196
5197 d->flags&=~D_SELECTED;
5198
5199 return D_O_K;
5200 }
5201
5202 void j_getstick(DIALOG *d)
5203 {
5204 d->flags|=D_SELECTED;
5205 jwin_button_proc(MSG_DRAW,d,0);
5206 jwin_draw_win(screen, (screen->w-160)/2, (screen->h-48)/2, 160, 48, FR_WIN);
5207 // text_mode(vc(11));
5208 int32_t y = screen->h/2 - 12;
5209 textout_centre_ex(screen, font, "Move a stick (or DPAD)", screen->w/2, y, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5210 textout_centre_ex(screen, font, "ESC to cancel", screen->w/2, y+8, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5211 textout_centre_ex(screen, font, "SPACE to disable", screen->w/2, y+16, jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5212
5213 update_hw_screen();
5214
5215 int32_t b = next_joy_input(false);
5216
5217 if(b>=0)
5218 *((int32_t*)d->dp3) = b;
5219
5220 d->flags&=~D_SELECTED;
5221 }
5222
5223 int32_t d_jbutton_proc(int32_t msg,DIALOG *d,int32_t c)
5224 {
5225 switch(msg)
5226 {
5227 case MSG_KEY:
5228 case MSG_CLICK:
5229
5230 int ret = j_getbtn(d);
5231 if (ret != D_O_K)
5232 return ret;
5233
5234 while(gui_mouse_b()) {
5235 rest(1);
5236 clear_keybuf();
5237 }
5238
5239 return D_REDRAW;
5240 }
5241
5242 return jwin_button_proc(msg,d,c);
5243 }
5244
5245 int32_t d_jstick_proc(int32_t msg,DIALOG *d,int32_t c)
5246 {
5247 switch(msg)
5248 {
5249 case MSG_KEY:
5250 case MSG_CLICK:
5251
5252 j_getstick(d);
5253
5254 while(gui_mouse_b()) {
5255 rest(1);
5256 clear_keybuf();
5257 }
5258
5259 return D_REDRAW;
5260 }
5261
5262 return jwin_button_proc(msg,d,c);
5263 }
5264
5265 //shnarf
5266 extern const char *key_str[];
5267 std::string get_keystr(int key);
5268
5269 const char *pan_str[4] = { " MONO", " 1/2", " 3/4", " FULL" };
5270
5271 static char str_a[80],str_b[80],str_s[80],str_m[80],str_l[80],str_r[80],str_p[80],str_ex1[80],str_ex2[80],str_ex3[80],str_ex4[80],
5272 str_leftmod1[80],str_leftmod2[80],str_rightmod1[80],str_rightmod2[80], str_left[80], str_right[80], str_up[80], str_down[80],
5273 str_primary_stick[80], str_secondary_stick[80];
5274
5275 int32_t d_stringloader(int32_t msg,DIALOG *d,int32_t c)
5276 {
5277 //these are here to bypass compiler warnings about unused arguments
5278 c=c;
5279
5280 if (d->w == 1)
5281 {
5282 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
5283 {
5284 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
5285 return D_CLOSE;
5286 }
5287 }
5288
5289 if(msg==MSG_DRAW)
5290 {
5291 switch(d->w)
5292 {
5293 case 0:
5294 sprintf(str_a,"%03d\n%s",Akey,key_str[Akey]);
5295 sprintf(str_b,"%03d\n%s",Bkey,key_str[Bkey]);
5296 sprintf(str_s,"%03d\n%s",Skey,key_str[Skey]);
5297 sprintf(str_l,"%03d\n%s",Lkey,key_str[Lkey]);
5298 sprintf(str_r,"%03d\n%s",Rkey,key_str[Rkey]);
5299 sprintf(str_p,"%03d\n%s",Pkey,key_str[Pkey]);
5300 sprintf(str_ex1,"%03d\n%s",Exkey1,key_str[Exkey1]);
5301 sprintf(str_ex2,"%03d\n%s",Exkey2,key_str[Exkey2]);
5302 sprintf(str_ex3,"%03d\n%s",Exkey3,key_str[Exkey3]);
5303 sprintf(str_ex4,"%03d\n%s",Exkey4,key_str[Exkey4]);
5304 sprintf(str_up,"%03d\n%s",DUkey,key_str[DUkey]);
5305 sprintf(str_down,"%03d\n%s",DDkey,key_str[DDkey]);
5306 sprintf(str_left,"%03d\n%s",DLkey,key_str[DLkey]);
5307 sprintf(str_right,"%03d\n%s",DRkey,key_str[DRkey]);
5308 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5309 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5310 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5311 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5312 break;
5313
5314 case 1:
5315 sprintf(str_a,"%03d\n%s",Abtn,joybtn_name(Abtn));
5316 sprintf(str_b,"%03d\n%s",Bbtn,joybtn_name(Bbtn));
5317 sprintf(str_s,"%03d\n%s",Sbtn,joybtn_name(Sbtn));
5318 sprintf(str_l,"%03d\n%s",Lbtn,joybtn_name(Lbtn));
5319 sprintf(str_r,"%03d\n%s",Rbtn,joybtn_name(Rbtn));
5320 sprintf(str_m,"%03d\n%s",Mbtn,joybtn_name(Mbtn));
5321 sprintf(str_p,"%03d\n%s",Pbtn,joybtn_name(Pbtn));
5322 sprintf(str_ex1,"%03d\n%s",Exbtn1,joybtn_name(Exbtn1));
5323 sprintf(str_ex2,"%03d\n%s",Exbtn2,joybtn_name(Exbtn2));
5324 sprintf(str_ex3,"%03d\n%s",Exbtn3,joybtn_name(Exbtn3));
5325 sprintf(str_ex4,"%03d\n%s",Exbtn4,joybtn_name(Exbtn4));
5326 sprintf(str_up,"%03d\n%s",DUbtn,joybtn_name(DUbtn));
5327 sprintf(str_down,"%03d\n%s",DDbtn,joybtn_name(DDbtn));
5328 sprintf(str_left,"%03d\n%s",DLbtn,joybtn_name(DLbtn));
5329 sprintf(str_right,"%03d\n%s",DRbtn,joybtn_name(DRbtn));
5330 sprintf(str_primary_stick,"%03d\n%s",js_stick_1_x_stick,joystick_name(js_stick_1_x_stick));
5331 sprintf(str_secondary_stick,"%03d\n%s",js_stick_2_x_stick,joystick_name(js_stick_2_x_stick));
5332 sprintf(str_leftmod1,"%03d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5333 sprintf(str_leftmod2,"%03d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5334 sprintf(str_rightmod1,"%03d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5335 sprintf(str_rightmod2,"%03d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5336 break;
5337
5338 case 2:
5339 sprintf(str_a," %3d",midi_volume);
5340 sprintf(str_l," %3d",emusic_volume);
5341 sprintf(str_r," %3d",sfx_volume);
5342 strcpy(str_s,pan_str[pan_style]);
5343 sprintf(str_leftmod1,"%3d\n%s",cheat_modifier_keys[0],key_str[cheat_modifier_keys[0]]);
5344 sprintf(str_leftmod2,"%3d\n%s",cheat_modifier_keys[1],key_str[cheat_modifier_keys[1]]);
5345 sprintf(str_rightmod1,"%3d\n%s",cheat_modifier_keys[2],key_str[cheat_modifier_keys[2]]);
5346 sprintf(str_rightmod2,"%3d\n%s",cheat_modifier_keys[3],key_str[cheat_modifier_keys[3]]);
5347 break;
5348 }
5349 }
5350
5351 return D_O_K;
5352 }
5353
5354 int32_t set_vol(void *dp3, int32_t d2)
5355 {
5356 switch(((int32_t*)dp3)[0])
5357 {
5358 case 0:
5359 midi_volume = zc_min(d2<<3,255);
5360 break;
5361
5362 case 1:
5363 digi_volume = zc_min(d2<<3,255);
5364 break;
5365
5366 case 2:
5367 emusic_volume = zc_min(d2<<3,255);
5368 break;
5369
5370 case 3:
5371 sfx_volume = zc_min(d2<<3,255);
5372 break;
5373 }
5374
5375 // text_mode(vc(11));
5376 textprintf_right_ex(screen,get_zc_font(font_lfont_l), ((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]," %3d",zc_min(d2<<3,255));
5377 return D_O_K;
5378 }
5379
5380 int32_t set_pan(void *dp3, int32_t d2)
5381 {
5382 pan_style = vbound(d2,0,3);
5383 // text_mode(vc(11));
5384 textout_right_ex(screen,get_zc_font(font_lfont_l), pan_str[pan_style],((int32_t*)dp3)[1],((int32_t*)dp3)[2],jwin_pal[jcBOXFG],jwin_pal[jcBOX]);
5385 return D_O_K;
5386 }
5387
5388 static int32_t gamepad_joys_list[] =
5389 {
5390 61,
5391 -1
5392 };
5393
5394 static int32_t gamepad_btn_list[] =
5395 {
5396 6,
5397 7,8,9,10,11,12,13,14,15,16,17,
5398 18,19,20,21,22,23,24,25,26,27,28,
5399 29,30,31,32,33,34,35,36,37,38,39,
5400 -1
5401 };
5402
5403 static int32_t gamepad_dirs_list[] =
5404 {
5405 40,41,42,43,
5406 44,45,46,47,
5407 48,49,50,51,
5408 52,53,54,55,
5409 56,57,58,59,
5410 60,
5411 -1
5412 };
5413
5414 static TABPANEL gamepad_tabs[] =
5415 {
5416 // (text)
5417 { (char *)"Controllers", D_SELECTED, gamepad_joys_list, 0, NULL },
5418 { (char *)"Buttons", 0, gamepad_btn_list, 0, NULL },
5419 { (char *)"Directions", 0, gamepad_dirs_list, 0, NULL },
5420 { NULL, 0, NULL, 0, NULL }
5421 };
5422
5423 const char *joy_list(int32_t index, int32_t *list_size)
5424 {
5425 if (index == -1)
5426 {
5427 *list_size = al_get_num_joysticks();
5428 return NULL;
5429 }
5430
5431 ALLEGRO_JOYSTICK* joy = al_get_joystick(index);
5432 if (!joy)
5433 {
5434 return "?";
5435 }
5436
5437 return al_get_joystick_name(joy);
5438 }
5439
5440 414 static ListData joy__list(joy_list, &font);
5441
5442 static int32_t d_joylist_proc(int32_t msg,DIALOG *d,int32_t c)
5443 {
5444 int32_t d2 = d->d2;
5445 int32_t ret = jwin_droplist_proc(msg,d,c);
5446
5447 if(d2!=d->d2)
5448 {
5449 joystick_index = d->d2;
5450 ret |= D_REDRAW_ALL;
5451 }
5452
5453 return ret;
5454 }
5455
5456 static DIALOG gamepad_dlg[] =
5457 {
5458 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5459 { jwin_win_proc, 8, 24, 304, 256, 0, 0, 0, D_EXIT, 0, 0, (void *) "Gamepad Controls", NULL, NULL },
5460 { jwin_tab_proc, 8+4, 24+23,304-8,256-52,vc(0), vc(15), 0, 0, 0, 0, (void *) gamepad_tabs, NULL, (void *)gamepad_dlg },
5461 { d_stringloader, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5462 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5463 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5464 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5465 // 6
5466 { d_dummy_proc, 14, 61, 294, 192, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5467 // 7
5468 { jwin_ctext_proc, 92, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5469 { jwin_ctext_proc, 92, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5470 { jwin_ctext_proc, 92, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5471 { jwin_ctext_proc, 92, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5472 { jwin_ctext_proc, 92, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5473 { jwin_ctext_proc, 237, 92-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5474 { jwin_ctext_proc, 237, 120-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5475 { jwin_ctext_proc, 237, 148-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5476 { jwin_ctext_proc, 237, 180-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5477 { jwin_ctext_proc, 237, 212-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5478 { jwin_ctext_proc, 92, 244-20, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_m, NULL, NULL },
5479 // 18
5480 { d_jbutton_proc, 22, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Abtn},
5481 { d_jbutton_proc, 22, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bbtn},
5482 { d_jbutton_proc, 22, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Sbtn},
5483 { d_jbutton_proc, 22, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exbtn1},
5484 { d_jbutton_proc, 22, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exbtn3},
5485 { d_jbutton_proc, 167, 90-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lbtn},
5486 { d_jbutton_proc, 167, 118-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rbtn},
5487 { d_jbutton_proc, 167, 146-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pbtn},
5488 { d_jbutton_proc, 167, 178-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exbtn2},
5489 { d_jbutton_proc, 167, 210-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exbtn4},
5490 { d_jbutton_proc, 22, 242-20, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Menu", NULL, &Mbtn},
5491 // 29
5492 { d_j_clearbutton_proc, 22+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Abtn},
5493 { d_j_clearbutton_proc, 22+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bbtn},
5494 { d_j_clearbutton_proc, 22+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Sbtn},
5495 { d_j_clearbutton_proc, 22+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn1},
5496 { d_j_clearbutton_proc, 22+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn3},
5497 { d_j_clearbutton_proc, 167+91, 90-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lbtn},
5498 { d_j_clearbutton_proc, 167+91, 118-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rbtn},
5499 { d_j_clearbutton_proc, 167+91, 146-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pbtn},
5500 { d_j_clearbutton_proc, 167+91, 178-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn2},
5501 { d_j_clearbutton_proc, 167+91, 210-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exbtn4},
5502 { d_j_clearbutton_proc, 22+91, 242-20, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Mbtn},
5503 // 40
5504 { jwin_frame_proc, 14, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5505 { jwin_frame_proc, 159, 62, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5506 { jwin_text_proc, 30, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5507 { jwin_text_proc, 175, 68, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5508 // 44
5509 { jwin_text_proc, 92, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5510 { jwin_text_proc, 92, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5511 { jwin_text_proc, 237, 84, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5512 { jwin_text_proc, 237, 112, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5513 // 48
5514 { d_jbutton_proc, 22, 82, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUbtn },
5515 { d_jbutton_proc, 22, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDbtn },
5516 { d_jbutton_proc, 167, 82, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLbtn },
5517 { d_jbutton_proc, 167, 110, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRbtn },
5518 // 52
5519 { d_j_clearbutton_proc, 22+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUbtn},
5520 { d_j_clearbutton_proc, 22+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDbtn},
5521 { d_j_clearbutton_proc, 167+91, 82, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLbtn},
5522 { d_j_clearbutton_proc, 167+91, 110, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRbtn},
5523 // 56
5524 { jwin_check_proc, 22, 150, 147, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Primary: Use Analog Stick (Ignore above and use below instead)", NULL, NULL },
5525 { d_jstick_proc, 22, 165, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Primary", NULL, &js_stick_1_x_stick },
5526 { d_jstick_proc, 22, 195, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Secondary", NULL, &js_stick_2_x_stick },
5527 { jwin_text_proc, 90, 165, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_primary_stick, NULL, NULL },
5528 { jwin_text_proc, 90, 195, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_secondary_stick, NULL, NULL },
5529
5530 // 61
5531 { d_joylist_proc, 22, 62, 150, 16, 0, 0, 0, 0, 0, 0, (void *) &joy__list, NULL, NULL },
5532
5533 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5534 };
5535
5536 static int32_t keyboard_keys_list[] =
5537 {
5538 6,7,8,9,10,
5539 11,12,13,14,15,16,17,18,19,20,
5540 21,22,23,24,25,26,27,28,29,30,
5541 31,32,33,34,35,36,37,38,39,40,
5542 -1
5543 };
5544
5545 static int32_t keyboard_dirs_list[] =
5546 {
5547 41,42,43,44,
5548 45,46,47,48,
5549 49,50,51,52,
5550 53,54,55,56,
5551 -1
5552 };
5553
5554 static int32_t keyboard_mods_list[] =
5555 {
5556 57,58,59,60,
5557 61,62,63,64,
5558 65,66,67,68,
5559 69,70,71,72,
5560 -1
5561 };
5562
5563 static TABPANEL keyboard_control_tabs[] =
5564 {
5565 // (text)
5566 { (char *)"Keys", D_SELECTED, keyboard_keys_list, 0, NULL },
5567 { (char *)"Directions", 0, keyboard_dirs_list, 0, NULL },
5568 { (char *)"Cheat Mods", 0, keyboard_mods_list, 0, NULL },
5569 { NULL, 0, NULL, 0, NULL }
5570 };
5571
5572 static DIALOG keyboard_control_dlg[] =
5573 {
5574 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5575 { jwin_win_proc, 8, 39, 304, 240, 0, 0, 0, D_EXIT, 0, 0, (void *) "Keyboard Controls", NULL, NULL },
5576 { jwin_tab_proc, 8+4, 39+23,304-8,240-56,vc(0), vc(15), 0, 0, 0, 0, (void *) keyboard_control_tabs, NULL, (void *)keyboard_control_dlg },
5577 { d_stringloader, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5578 { jwin_button_proc, 90, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5579 { jwin_button_proc, 170, 254, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5580 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5581 // Keys
5582 // 6
5583 { jwin_frame_proc, 14, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5584 { jwin_frame_proc, 158, 80, 148, 105, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5585 { jwin_frame_proc, 14, 181, 292, 67, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5586 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Standard", NULL, NULL },
5587 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Extended", NULL, NULL },
5588 // 11
5589 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5590 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_b, NULL, NULL },
5591 { jwin_text_proc, 92-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5592 { jwin_text_proc, 92-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex1, NULL, NULL },
5593 { jwin_text_proc, 92-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex3, NULL, NULL },
5594 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_l, NULL, NULL },
5595 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_r, NULL, NULL },
5596 { jwin_text_proc, 237-4, 158, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_p, NULL, NULL },
5597 { jwin_text_proc, 237-4, 190, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex2, NULL, NULL },
5598 { jwin_text_proc, 237-4, 222, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_ex4, NULL, NULL },
5599 // 21
5600 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "A", NULL, &Akey},
5601 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "B", NULL, &Bkey},
5602 { d_kbutton_proc, 22, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start", NULL, &Skey},
5603 { d_kbutton_proc, 22, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "X (EX1)", NULL, &Exkey1},
5604 { d_kbutton_proc, 22, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX3", NULL, &Exkey3},
5605 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "L", NULL, &Lkey},
5606 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "R", NULL, &Rkey},
5607 { d_kbutton_proc, 167, 156, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map", NULL, &Pkey},
5608 { d_kbutton_proc, 167, 188, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Y (EX2)", NULL, &Exkey2},
5609 { d_kbutton_proc, 167, 220, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "EX4", NULL, &Exkey4},
5610 // 31
5611 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Akey},
5612 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Bkey},
5613 { d_k_clearbutton_proc, 22+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Skey},
5614 { d_k_clearbutton_proc, 22+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey1},
5615 { d_k_clearbutton_proc, 22+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey3},
5616 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Lkey},
5617 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Rkey},
5618 { d_k_clearbutton_proc, 167+91, 156, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Pkey},
5619 { d_k_clearbutton_proc, 167+91, 188, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey2},
5620 { d_k_clearbutton_proc, 167+91, 220, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &Exkey4},
5621 // Dirs
5622 // 41
5623 { jwin_frame_proc, 14, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5624 { jwin_frame_proc, 159, 80, 147, 80, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5625 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Vertical", NULL, NULL },
5626 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Horizontal", NULL, NULL },
5627 // 45
5628 { jwin_text_proc, 92-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_up, NULL, NULL },
5629 { jwin_text_proc, 92-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_down, NULL, NULL },
5630 { jwin_text_proc, 237-4, 102, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_left, NULL, NULL },
5631 { jwin_text_proc, 237-4, 130, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_right, NULL, NULL },
5632 // 49
5633 { d_kbutton_proc, 22, 100, 61, 21, vc(14), vc(11), 0, 0, 0, 0, (void *) "Up", NULL, &DUkey},
5634 { d_kbutton_proc, 22, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Down", NULL, &DDkey},
5635 { d_kbutton_proc, 167, 100, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Left", NULL, &DLkey},
5636 { d_kbutton_proc, 167, 128, 61, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Right", NULL, &DRkey},
5637 // 53
5638 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DUkey},
5639 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DDkey},
5640 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DLkey},
5641 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &DRkey},
5642 // Mods
5643 // 57
5644 { jwin_frame_proc, 14, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5645 { jwin_frame_proc, 158, 80, 148, 140-58, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5646 { jwin_text_proc, 30, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Left", NULL, NULL },
5647 { jwin_text_proc, 175, 86, 160, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Right", NULL, NULL },
5648 // 61
5649 { jwin_text_proc, 92-26, 101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod1, NULL, NULL },
5650 { jwin_text_proc, 92-26, 129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod1, NULL, NULL },
5651 { jwin_text_proc, 237-4-22,101, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_leftmod2, NULL, NULL },
5652 { jwin_text_proc, 237-4-22,129, 60, 8, vc(7), vc(11), 0, 0, 0, 0, str_rightmod2, NULL, NULL },
5653 // 65
5654 { d_kbutton_proc, 22, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[0]},
5655 { d_kbutton_proc, 22, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[2]},
5656 { d_kbutton_proc, 167, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Main", NULL, &cheat_modifier_keys[1]},
5657 { d_kbutton_proc, 167, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Second", NULL, &cheat_modifier_keys[3]},
5658 // 69
5659 { d_k_clearbutton_proc, 22+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[0]},
5660 { d_k_clearbutton_proc, 22+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[2]},
5661 { d_k_clearbutton_proc, 167+91, 100, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[1]},
5662 { d_k_clearbutton_proc, 167+91, 128, 40, 21, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear", NULL, &cheat_modifier_keys[3]},
5663 // 73
5664 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5665 };
5666
5667 int32_t midi_dp[3] = {0,0,0};
5668 int32_t emus_dp[3] = {2,0,0};
5669 int32_t sfx_dp[3] = {3,0,0};
5670 int32_t pan_dp[3] = {0,0,0};
5671
5672 static DIALOG sound_dlg[] =
5673 {
5674 //(dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
5675 414 { jwin_win_proc, 0, 0, 320, 178, 0, 0, 0, D_EXIT, 0, 0, (void *) "Sound Settings", NULL, NULL },
5676 414 { d_stringloader, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5677 414 { jwin_button_proc, 58, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5678 414 { jwin_button_proc, 138, 148, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5679 414 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5680 414 { jwin_frame_proc, 10, 28, 300, 112, 0, 0, 0, 0, FR_ETCHED, 0, NULL, NULL, NULL },
5681 414 { jwin_rtext_proc, 190, 40, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_a, NULL, NULL },
5682 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5683 414 { jwin_rtext_proc, 190, 56, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_l, NULL, NULL },
5684 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5685 // 10
5686 414 { jwin_rtext_proc, 190, 72, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_r, NULL, NULL },
5687 414 { jwin_rtext_proc, 190, 88, 40, 8, vc(7), vc(11), 0, 0, 0, 0, (void *) str_s, NULL, NULL },
5688 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5689 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5690 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5691 414 { jwin_slider_proc, 196, 40, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, midi_dp },
5692 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5693 414 { jwin_slider_proc, 196, 56, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, emus_dp },
5694 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5695 414 { jwin_slider_proc, 196, 72, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 32, 0, NULL, (void *) set_vol, sfx_dp },
5696 //20
5697 414 { jwin_slider_proc, 196, 88, 96, 8, vc(0), jwin_pal[jcBOX], 0, 0, 3, 0, NULL, (void *) set_pan, pan_dp },
5698 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5699 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5700 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5701 414 { jwin_text_proc, 17, 40, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "MIDI Volume", NULL, NULL },
5702 414 { jwin_text_proc, 17, 56, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Music Volume (Enhanced Music)", NULL, NULL },
5703 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5704 414 { jwin_text_proc, 17, 72, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Volume", NULL, NULL },
5705 414 { jwin_text_proc, 17, 88, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "SFX Pan", NULL, NULL },
5706 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5707 //30
5708 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5709 414 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5710 414 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5711 };
5712
5713 char zc_builddate[80];
5714 char zc_aboutstr[80];
5715
5716 static DIALOG about_dlg[] =
5717 {
5718 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5719 { jwin_win_proc, 68, 52, 184, 154, 0, 0, 0, D_EXIT, 0, 0, (void *) "About", NULL, NULL },
5720 { jwin_button_proc, 140, 176, 41, 21, vc(14), 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
5721 { jwin_ctext_proc, 160, 84, 0, 8, vc(0), vc(11), 0, 0, 0, 0, zc_aboutstr, NULL, NULL },
5722 { jwin_ctext_proc, 160, 92, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5723 { jwin_ctext_proc, 160, 100, 0, 8, vc(0) , vc(11), 0, 0, 0, 0, zc_builddate, NULL, NULL },
5724 { jwin_text_proc, 88, 124, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Coded by:", NULL, NULL },
5725 { jwin_text_proc, 88, 132, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Phantom Menace", NULL, NULL },
5726 { jwin_text_proc, 88, 144, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Produced by:", NULL, NULL },
5727 { jwin_text_proc, 88, 152, 140, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) " Armageddon Games", NULL, NULL },
5728 { jwin_frame_proc, 80, 117, 160, 50, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5729 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5730 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5731 };
5732
5733
5734 static DIALOG quest_dlg[] =
5735 {
5736 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
5737 { jwin_win_proc, 68, 25, 184, 190, 0, 0, 0, D_EXIT, 0, 0, (void *) "Quest Info", NULL, NULL },
5738 { jwin_edit_proc, 84, 54, 152, 16, 0, 0, 0, D_READONLY, 100, 0, NULL, NULL, NULL },
5739 { jwin_text_proc, 89, 84, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
5740 { jwin_text_proc, 152, 84, 24, 8, vc(7), vc(11), 0, 0, 0, 0, str_a, NULL, NULL },
5741 { jwin_text_proc, 89, 94, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Version:", NULL, NULL },
5742 { jwin_text_proc, 160, 94, 64, 8, vc(7), vc(11), 0, 0, 0, 0, header_version_nul_term, NULL, NULL },
5743 { jwin_text_proc, 89, 104, 141, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "ZQ Version:", NULL, NULL },
5744 { jwin_text_proc, 130, 104, 64, 8, vc(7), vc(11), 0, 0, 0, 0, str_s, NULL, NULL },
5745 { jwin_text_proc, 84, 126, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Title:", NULL, NULL },
5746 { jwin_textbox_proc, 84, 136, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.title, NULL, NULL },
5747 { jwin_text_proc, 84, 168, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Author:", NULL, NULL },
5748 { jwin_textbox_proc, 84, 178, 152, 24, 0, 0, 0, 0, 0, 0, QHeader.author, NULL, NULL },
5749 { jwin_frame_proc, 84, 79, 152, 38, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
5750 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5751 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5752 };
5753
5754 static DIALOG triforce_dlg[] =
5755 {
5756 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
5757 { jwin_win_proc, 72, 64, 177, 105, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
5758 // 1
5759 { jwin_check_proc, 129, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "1", NULL, NULL },
5760 { jwin_check_proc, 129, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "2", NULL, NULL },
5761 { jwin_check_proc, 129, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "3", NULL, NULL },
5762 { jwin_check_proc, 129, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "4", NULL, NULL },
5763 { jwin_check_proc, 172, 94, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "5", NULL, NULL },
5764 { jwin_check_proc, 172, 104, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "6", NULL, NULL },
5765 { jwin_check_proc, 172, 114, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "7", NULL, NULL },
5766 { jwin_check_proc, 172, 124, 24, 9, vc(0), vc(11), 0, 0, 1, 0, (void *) "8", NULL, NULL },
5767 // 9
5768 { jwin_button_proc, 90, 144, 61, 21, vc(0), vc(11), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
5769 { jwin_button_proc, 170, 144, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
5770 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
5771 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
5772 };
5773
5774 int32_t onToggleRecordingNewSaves()
5775 {
5776 if (zc_get_config("zeldadx", "replay_new_saves", false))
5777 {
5778 zc_set_config("zeldadx", "replay_new_saves", false);
5779 }
5780 else
5781 {
5782 zc_set_config("zeldadx", "replay_new_saves", true);
5783 jwin_alert("Recording", "Newly created saves will be recorded and written to a replay file.",
5784 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5785 }
5786 return D_O_K;
5787 }
5788
5789 #ifdef HAS_CURL
5790 int32_t onToggleAutoUploadReplays()
5791 {
5792 if (zc_get_config("zeldadx", "replay_upload", false))
5793 {
5794 zc_set_config("zeldadx", "replay_upload", false);
5795 }
5796 else
5797 {
5798 zc_set_config("zeldadx", "replay_upload", true);
5799 jwin_alert("Replays", "Replays will be automatically uploaded. This helps development by",
5800 " preventing bugs and simplifying bug reports.",
5801 "Upload will happen no more than once a week when closing ZC",
5802 "OK",NULL,13,27,get_zc_font(font_lfont));
5803
5804 if (!zc_get_config("zeldadx", "replay_new_saves", false))
5805 onToggleRecordingNewSaves();
5806 }
5807 return D_O_K;
5808 }
5809
5810 int32_t onUploadReplays()
5811 {
5812 if(jwin_alert3(
5813 "Upload replays",
5814 "Upload your replays now to assist in development?",
5815 NULL,
5816 NULL,
5817 "&Yes",
5818 "&No",
5819 NULL,
5820 'y',
5821 'n',
5822 0,
5823 get_zc_font(font_lfont)) == 1)
5824 {
5825 int num_uploaded = replay_upload();
5826 jwin_alert("Upload replays", fmt::format("Uploaded {} replays", num_uploaded).c_str(),
5827 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5828 }
5829 return D_O_K;
5830 }
5831
5832 int32_t onClearUploadCache()
5833 {
5834 if(jwin_alert3(
5835 "Upload replays",
5836 "Clear the upload cache?",
5837 "This simply deletes replays/state.json. There's no harm in doing this, but",
5838 "likely is not necessary.",
5839 "&Yes",
5840 "&No",
5841 NULL,
5842 'y',
5843 'n',
5844 0,
5845 get_zc_font(font_lfont)) == 1)
5846 {
5847 replay_upload_clear_cache();
5848 }
5849 return D_O_K;
5850 }
5851 #endif
5852
5853 int32_t onToggleSnapshotAllFrames()
5854 {
5855 replay_set_snapshot_all_frames(!replay_is_snapshot_all_frames());
5856 return D_O_K;
5857 }
5858
5859 int32_t onStopReplayOrRecord()
5860 {
5861 if (replay_is_replaying())
5862 {
5863 replay_quit();
5864 }
5865 else if (replay_get_mode() == ReplayMode::Record)
5866 {
5867 if (!replay_get_meta_bool("test_mode"))
5868 {
5869 jwin_alert("Recording", "You cannot stop recording a save file.",
5870 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5871 return D_CLOSE;
5872 }
5873
5874 if (jwin_alert("Stop Recording",
5875 "Save replay to disk and stop recording?",
5876 "This will stop the recording.",
5877 NULL,
5878 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5879 return D_CLOSE;
5880
5881 replay_save();
5882 replay_stop();
5883 }
5884 return D_O_K;
5885 }
5886
5887 static int32_t handle_on_load_replay(ReplayMode mode)
5888 {
5889 bool ctrl = CHECK_CTRL_CMD;
5890 if (Playing)
5891 {
5892 if (jwin_alert("Replay - Warning!",
5893 "Loading a replay will exit the current game.",
5894 "All unsaved progress will be lost.",
5895 "Do you wish to continue?",
5896 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5897 return D_CLOSE;
5898 }
5899
5900 std::string mode_string = replay_mode_to_string(mode);
5901 mode_string[0] = std::toupper(mode_string[0]);
5902
5903 std::string line_1 = "Select a replay file to play back.";
5904 std::string line_2 = "You won't be able to save, and it won't effect existing saves.";
5905 std::string line_3 = "You can stop the replay and take over manually any time.";
5906 if (mode == ReplayMode::Update)
5907 {
5908 line_1 = "Select a replay file to update.";
5909 line_2 = "WARNING: be sure to back up the zplay file";
5910 line_3 = "and verify that the updated replay works as expected!";
5911 }
5912
5913 if (jwin_alert(mode_string.c_str(),
5914 line_1.c_str(),
5915 line_2.c_str(),
5916 line_3.c_str(),
5917 "OK","Nevermind",13,27,get_zc_font(font_lfont)) == 1)
5918 {
5919 std::string replay_path = "replays/";
5920 if(ctrl && devpwd())
5921 replay_path = "../../tests/replays/";
5922 std::string prompt = fmt::format("Load Replay ({})", REPLAY_EXTENSION);
5923 if (auto result = prompt_for_existing_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5924 replay_path = *result;
5925 else
5926 return D_CLOSE;
5927
5928 replay_quit();
5929 load_replay_file_deferred(mode, replay_path);
5930 Quit = qRESET;
5931 return D_CLOSE;
5932 }
5933 return D_O_K;
5934 }
5935
5936 int32_t onLoadReplay()
5937 {
5938 return handle_on_load_replay(ReplayMode::Replay);
5939 }
5940
5941 int32_t onLoadReplayAssert()
5942 {
5943 return handle_on_load_replay(ReplayMode::Assert);
5944 }
5945
5946 int32_t onLoadReplayUpdate()
5947 {
5948 return handle_on_load_replay(ReplayMode::Update);
5949 }
5950
5951 int32_t onSaveReplay()
5952 {
5953 if (replay_get_mode() == ReplayMode::Record)
5954 {
5955 if (!replay_get_meta_bool("test_mode"))
5956 {
5957 if (jwin_alert("Save Replay",
5958 "This will save a copy of the replay up to this point.",
5959 "The official replay file will be untouched.",
5960 "Do you wish to continue?",
5961 "Yes","No",13,27,get_zc_font(font_lfont)) != 1)
5962 {
5963 return D_CLOSE;
5964 }
5965
5966 std::string replay_path = replay_get_replay_path().string();
5967 std::string prompt = fmt::format("Save Replay ({})", REPLAY_EXTENSION);
5968 if (auto result = prompt_for_new_file(prompt, REPLAY_EXTENSION, nullptr, replay_path))
5969 replay_path = *result;
5970 else
5971 return D_CLOSE;
5972
5973 if (fileexists(replay_path.c_str()))
5974 {
5975 jwin_alert("Save Replay", "You cannot overwrite an existing file.",
5976 NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
5977 return D_CLOSE;
5978 }
5979
5980 replay_save(replay_path);
5981 }
5982 else
5983 {
5984 replay_save();
5985 }
5986 }
5987 return D_O_K;
5988 }
5989
5990 enum
5991 {
5992 MENUID_REPLAY_RECORDNEW,
5993 MENUID_REPLAY_STOP,
5994 MENUID_REPLAY_SAVE,
5995 MENUID_REPLAY_SNAP_ALL,
5996 MENUID_REPLAY_AUTOUPLOAD,
5997 MENUID_REPLAY_UPLOAD,
5998 MENUID_REPLAY_CLEARUPLOADCACHE,
5999 };
6000
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu replay_menu
6001 5382 {
6002
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Record new saves", onToggleRecordingNewSaves, MENUID_REPLAY_RECORDNEW },
6003
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
6004
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Stop replay", onStopReplayOrRecord, MENUID_REPLAY_STOP },
6005
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Load replay", onLoadReplay },
6006
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Load replay (assert)", onLoadReplayAssert },
6007
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Load replay (update)", onLoadReplayUpdate },
6008
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save replay", onSaveReplay, MENUID_REPLAY_SAVE },
6009
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Snapshot all frames", onToggleSnapshotAllFrames, MENUID_REPLAY_SNAP_ALL },
6010 #ifdef HAS_CURL
6011
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
6012
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Auto upload replays", onToggleAutoUploadReplays, MENUID_REPLAY_AUTOUPLOAD },
6013
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Upload replays", onUploadReplays, MENUID_REPLAY_UPLOAD },
6014
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Clear upload cache", onClearUploadCache, MENUID_REPLAY_CLEARUPLOADCACHE },
6015 #endif
6016 };
6017
6018 static DIALOG credits_dlg[] =
6019 {
6020 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6021 { jwin_win_proc, 40, 38, 241, 173, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "ZQuest Classic Credits", NULL, NULL },
6022 { jwin_frame_proc, 47, 65, 227, 115, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
6023 { d_bitmap_proc, 49, 67, 222, 110, vc(15), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
6024 { jwin_button_proc, 140, 184, 41, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6025 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6026 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6027 };
6028
6029 414 static ListData dmap_list(dmaplist, &font);
6030
6031 static DIALOG goto_dlg[] =
6032 {
6033 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6034 { jwin_win_proc, 48, 25, 205, 100, 0, 0, 0, D_EXIT, 0, 0, (void *) "Goto Location", NULL, NULL },
6035 { jwin_button_proc, 90, 176-78, 61, 21, vc(14), 0, 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6036 { jwin_button_proc, 170, 176-78, 61, 21, vc(14), 0, 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6037 { jwin_text_proc, 55, 129-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
6038 { jwin_droplist_proc, 88, 126-75, 160, 16, 0, 0, 0, 0, 0, 0, (void *) &dmap_list, NULL, NULL },
6039 { jwin_text_proc, 55, 149-75, 80, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
6040 { jwin_edit_proc, 132, 146-75, 91, 16, 0, 0, 0, 0, 2, 0, NULL, NULL, NULL },
6041 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6042 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6043 };
6044
6045 int32_t onGoTo()
6046 {
6047 bool music = false;
6048 music = music;
6049 sprintf(cheat_goto_screen_str,"%X",cheat_goto_screen);
6050
6051 goto_dlg[0].dp2=get_zc_font(font_lfont);
6052 goto_dlg[4].d2=cheat_goto_dmap;
6053 goto_dlg[6].dp=cheat_goto_screen_str;
6054
6055 clear_keybuf();
6056
6057 large_dialog(goto_dlg);
6058
6059 if(do_zqdialog(goto_dlg,4)==1)
6060 {
6061 int dmap = goto_dlg[4].d2;
6062 int screen = zc_xtoi(cheat_goto_screen_str);
6063 int adjusted_screen = screen + DMaps[dmap].xoff;
6064 if (adjusted_screen < 0 || adjusted_screen >= 128)
6065 {
6066 InfoDialog("Invalid screen", fmt::format("The screen {:02X} is out of bounds.", adjusted_screen)).show();
6067 }
6068 else
6069 {
6070 cheats_enqueue(Cheat::GoTo, dmap, screen);
6071 }
6072 };
6073
6074 return D_O_K;
6075 }
6076
6077 int32_t onGoToComplete()
6078 {
6079 if(!Playing)
6080 {
6081 return D_O_K;
6082 }
6083
6084 enter_sys_pal();
6085 music_pause();
6086 pause_all_sfx();
6087 onGoTo();
6088 eat_buttons();
6089
6090 zc_readrawkey(KEY_ESC);
6091
6092 exit_sys_pal();
6093 music_resume();
6094 resume_all_sfx();
6095 return D_O_K;
6096 }
6097
6098 int32_t onCredits()
6099 {
6100 return D_O_K;
6101 }
6102
6103 const char *midilist(int32_t index, int32_t *list_size)
6104 {
6105 if(index<0)
6106 {
6107 *list_size=0;
6108
6109 for(int32_t i=0; i<MAXMIDIS; i++)
6110 if(tunes[i].data)
6111 ++(*list_size);
6112
6113 return NULL;
6114 }
6115
6116 int32_t i=0,m=0;
6117
6118 while(m<=index && i<=MAXMIDIS)
6119 {
6120 if(tunes[i].data)
6121 ++m;
6122
6123 ++i;
6124 }
6125
6126 --i;
6127
6128 if(i==MAXMIDIS && m<index)
6129 return "(null)";
6130
6131 return tunes[i].title;
6132 }
6133
6134 /* ------- MIDI info stuff -------- */
6135
6136 char *text;
6137 midi_info *zmi;
6138 bool dialog_running;
6139 bool listening;
6140
6141 void get_info(int32_t index);
6142
6143 int32_t d_midilist_proc(int32_t msg,DIALOG *d,int32_t c)
6144 {
6145 int32_t d2 = d->d2;
6146 int32_t ret = jwin_droplist_proc(msg,d,c);
6147
6148 if(d2!=d->d2)
6149 {
6150 get_info(d->d2);
6151 }
6152
6153 return ret;
6154 }
6155
6156 int32_t d_listen_proc(int32_t msg,DIALOG *d,int32_t c)
6157 {
6158 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6159
6160 int32_t ret = jwin_button_proc(msg,d,c);
6161
6162 if(ret == D_CLOSE)
6163 {
6164 // get current midi index
6165 int32_t index = (d+(d->d1))->d2;
6166 int32_t i=0, m=0;
6167
6168 while(m<=index && i<=MAXMIDIS)
6169 {
6170 if(tunes[i].data)
6171 ++m;
6172
6173 ++i;
6174 }
6175
6176 --i;
6177 jukebox(i);
6178 listening = true;
6179 ret = D_O_K;
6180 }
6181
6182 return ret;
6183 }
6184
6185 int32_t d_savemidi_proc(int32_t msg,DIALOG *d,int32_t c)
6186 {
6187 /* 'd->d1' is offset from 'd' in DIALOG array to midilist proc */
6188
6189 int32_t ret = jwin_button_proc(msg,d,c);
6190
6191 if(ret == D_CLOSE)
6192 {
6193 // get current midi index
6194 int32_t index = (d+(d->d1))->d2;
6195 int32_t i=0, m=0;
6196
6197 while(m<=index && i<=MAXMIDIS)
6198 {
6199 if(tunes[i].data)
6200 ++m;
6201
6202 ++i;
6203 }
6204
6205 --i;
6206
6207 char title[40] = "Save MIDI: ";
6208 static EXT_LIST list[] =
6209 {
6210 { (char *)"MIDI files (*.mid)", (char *)"mid" },
6211 { NULL, NULL }
6212 };
6213
6214 strcpy(title+11, tunes[i].title);
6215 title[39] = '\0';
6216
6217 std::string fname;
6218 if (auto result = prompt_for_new_file(title, "", list, "tune.mid"))
6219 fname = *result;
6220 else
6221 goto done;
6222
6223 if(exists(fname.c_str()))
6224 {
6225 if(jwin_alert(title, fname.c_str(), "already exists.", "Overwrite it?", "&Yes","&No",'y','n',get_zc_font(font_lfont))==2)
6226 goto done;
6227 }
6228
6229 // save midi i
6230
6231 if (save_midi(fname.c_str(), tunes[i].data) != 0)
6232 jwin_alert(title, "Error saving MIDI to", fname.c_str(), NULL, "Darn", NULL,13,27,get_zc_font(font_lfont));
6233
6234 done:
6235 chop_path(fname.data());
6236 ret = D_REDRAW;
6237 }
6238
6239 return ret;
6240 }
6241
6242 414 static ListData midi_list(midilist, &font);
6243
6244 static DIALOG midi_dlg[] =
6245 {
6246 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
6247 { jwin_win_proc, 8, 28, 304, 184, 0, 0, 0, D_EXIT, 0, 0, (void *) "MIDI Info", NULL, NULL },
6248 { jwin_text_proc, 32, 60, 40, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Tune:", NULL, NULL },
6249 { d_midilist_proc, 80, 56, 192, 16, 0, 0, 0, 0, 0, 0, (void *) &midi_list, NULL, NULL },
6250 { jwin_textbox_proc, 15, 80, 290, 96, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6251 { d_listen_proc, 24, 183, 72, 21, 0, 0, 'l', D_EXIT, -2, 0, (void *) "&Listen", NULL, NULL },
6252 { d_savemidi_proc, 108, 183, 72, 21, 0, 0, 's', D_EXIT, -3, 0, (void *) "&Save", NULL, NULL },
6253 { jwin_button_proc, 236, 183, 61, 21, 0, 0, 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
6254 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6255 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6256 };
6257
6258 void get_info(int32_t index)
6259 {
6260 int32_t i=0, m=0;
6261
6262 while(m<=index && i<=MAXMIDIS)
6263 {
6264 if(tunes[i].data)
6265 ++m;
6266
6267 ++i;
6268 }
6269
6270 --i;
6271
6272 if(i==MAXMIDIS && m<index)
6273 strcpy(text,"(null)");
6274 else
6275 {
6276 get_midi_info(tunes[i].data,zmi);
6277 get_midi_text(tunes[i].data,zmi,text);
6278 }
6279
6280 midi_dlg[0].dp2=get_zc_font(font_lfont);
6281 midi_dlg[3].dp = text;
6282 midi_dlg[3].d1 = midi_dlg[3].d2 = 0;
6283 midi_dlg[5].flags = (tunes[i].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6284
6285 if(dialog_running)
6286 {
6287 jwin_textbox_proc(MSG_DRAW,midi_dlg+3,0);
6288 d_savemidi_proc(MSG_DRAW,midi_dlg+5,0);
6289 }
6290 }
6291
6292 int32_t onMIDICredits()
6293 {
6294 text = (char*)malloc(4096);
6295 zmi = (midi_info*)malloc(sizeof(midi_info));
6296
6297 if(!text || !zmi)
6298 {
6299 jwin_alert(NULL,"Not enough memory",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
6300 return D_O_K;
6301 }
6302
6303 bool do_pause_midi = midi_pos >= 0 && currmidi;
6304 auto restore_midi = currmidi;
6305 if(do_pause_midi)
6306 {
6307 paused_midi_pos = midi_pos;
6308 stop_midi();
6309 midi_suspended = midissuspHALTED;
6310 }
6311
6312 midi_dlg[0].dp2=get_zc_font(font_lfont);
6313 midi_dlg[2].d1 = 0;
6314 midi_dlg[2].d2 = 0;
6315 midi_dlg[4].flags = D_EXIT;
6316 midi_dlg[5].flags = (tunes[midi_dlg[2].d1].flags&tfDISABLESAVE) ? D_DISABLED : D_EXIT;
6317
6318 listening = false;
6319 dialog_running=false;
6320 get_info(0);
6321
6322 dialog_running=true;
6323
6324 large_dialog(midi_dlg);
6325
6326 do_zqdialog(midi_dlg,0);
6327 dialog_running=false;
6328
6329 if(listening)
6330 music_stop();
6331
6332 if(do_pause_midi)
6333 {
6334 // TODO: this probably doesn't resume midis nicely when scrolling (or in some other inner-gameloop).
6335 midi_suspended = midissuspRESUME;
6336 currmidi = restore_midi;
6337 midi_pos = paused_midi_pos;
6338 }
6339
6340 if(text) free(text);
6341 if(zmi) free(zmi);
6342 return D_O_K;
6343 }
6344
6345 int32_t onAbout()
6346 {
6347 char buf1[80]={0};
6348 std::ostringstream oss;
6349 sprintf(buf1,"ZQuest Classic Player");
6350 oss << buf1 << '\n';
6351 sprintf(buf1,"Version: %s", getVersionString());
6352 oss << buf1 << '\n';
6353 sprintf(buf1,"Build Date: %s %s, %d at @ %s %s", dayextension(BUILDTM_DAY).c_str(), (char*)months[BUILDTM_MONTH], BUILDTM_YEAR, __TIME__, __TIMEZONE__);
6354 oss << buf1 << '\n';
6355
6356 InfoDialog("About ZC", oss.str()).show();
6357 return D_O_K;
6358 }
6359
6360 int32_t onQuest()
6361 {
6362 char fname[100];
6363 strcpy(fname, get_filename(qstpath));
6364 quest_dlg[0].dp2=get_zc_font(font_lfont);
6365 quest_dlg[1].dp = fname;
6366
6367 if(QHeader.quest_number==0)
6368 sprintf(str_a,"Custom");
6369 else
6370 sprintf(str_a,"%d",QHeader.quest_number);
6371
6372 sprintf(str_s,"%s",QHeader.getVerStr());
6373
6374 quest_dlg[11].d1 = quest_dlg[9].d1 = 0;
6375 quest_dlg[11].d2 = quest_dlg[9].d2 = 0;
6376
6377 large_dialog(quest_dlg);
6378
6379 do_zqdialog(quest_dlg, 0);
6380 return D_O_K;
6381 }
6382
6383 void call_vidmode_dlg();
6384 int32_t onVidMode()
6385 {
6386 call_vidmode_dlg();
6387 return D_O_K;
6388 }
6389
6390 #define addToHash(c,b,h) if(h->find(c ## key) == h->end()) \
6391 {(*h)[c ## key]=true;} else { if ( c ## key != 0 ) b = false;}
6392 //Added an extra statement, so that if the key is cleared to 0, the cleared
6393 //keybinding status need not be unique. -Z ( 1st April, 2019 )
6394
6395 void load_ukeys(int32_t* arr)
6396 {
6397 arr[ukey_a] = Akey;
6398 arr[ukey_b] = Bkey;
6399 arr[ukey_s] = Skey;
6400 arr[ukey_l] = Lkey;
6401 arr[ukey_r] = Rkey;
6402 arr[ukey_p] = Pkey;
6403 arr[ukey_ex1] = Exkey1;
6404 arr[ukey_ex2] = Exkey2;
6405 arr[ukey_ex3] = Exkey3;
6406 arr[ukey_ex4] = Exkey4;
6407 arr[ukey_du] = DUkey;
6408 arr[ukey_dd] = DDkey;
6409 arr[ukey_dl] = DLkey;
6410 arr[ukey_dr] = DRkey;
6411 arr[ukey_mod1a] = cheat_modifier_keys[0];
6412 arr[ukey_mod1b] = cheat_modifier_keys[1];
6413 arr[ukey_mod2a] = cheat_modifier_keys[2];
6414 arr[ukey_mod2b] = cheat_modifier_keys[3];
6415 };
6416
6417 static const char* ukey_names[] = {
6418 "A", "B", "Start", "L", "R", "Map",
6419 "Ex1", "Ex2", "Ex3", "Ex4", "Up", "Down",
6420 "Left", "Right", "Cheat Mod L1", "Cheat Mod L2",
6421 "Cheat Mod R1", "Cheat Mod R2",
6422 };
6423 std::string get_ukey_name(int32_t k)
6424 {
6425 if (k < num_ukey) return ukey_names[k];
6426 return "";
6427 }
6428
6429 int32_t onKeyboard()
6430 {
6431 int32_t a = Akey;
6432 int32_t b = Bkey;
6433 int32_t s = Skey;
6434 int32_t l = Lkey;
6435 int32_t r = Rkey;
6436 int32_t p = Pkey;
6437 int32_t ex1 = Exkey1;
6438 int32_t ex2 = Exkey2;
6439 int32_t ex3 = Exkey3;
6440 int32_t ex4 = Exkey4;
6441 int32_t du = DUkey;
6442 int32_t dd = DDkey;
6443 int32_t dl = DLkey;
6444 int32_t dr = DRkey;
6445 int32_t mod1a = cheat_modifier_keys[0];
6446 int32_t mod1b = cheat_modifier_keys[1];
6447 int32_t mod2a = cheat_modifier_keys[2];
6448 int32_t mod2b = cheat_modifier_keys[3];
6449 bool done=false;
6450 int32_t ret;
6451
6452 keyboard_control_dlg[0].dp2=get_zc_font(font_lfont);
6453
6454 large_dialog(keyboard_control_dlg);
6455
6456 while(!done)
6457 {
6458 ret = do_zqdialog(keyboard_control_dlg,3);
6459
6460 if(ret==3) // OK
6461 {
6462 int32_t ukeys[num_ukey];
6463 load_ukeys(ukeys);
6464 std::vector<std::string> uniqueError;
6465 for(int32_t q = 0; q < num_ukey; ++q)
6466 {
6467 for(int32_t p = q+1; p < num_ukey; ++p)
6468 {
6469 if(ukeys[q] == ukeys[p] && ukeys[q] != 0)
6470 {
6471 char buf[64];
6472 sprintf(buf, "'%s' conflicts with '%s'", get_ukey_name(q).c_str(), get_ukey_name(p).c_str());
6473 std::string str(buf);
6474 uniqueError.push_back(str);
6475 }
6476 }
6477 }
6478 if(uniqueError.size() == 0)
6479 {
6480 done = true;
6481 save_control_configs(true);
6482 }
6483 else
6484 {
6485 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, keyboard_control_dlg[0].w,keyboard_control_dlg[0].h, 2);
6486 box_out("Cannot have duplicate keybinds!"); box_eol();
6487 for(std::vector<std::string>::iterator it = uniqueError.begin();
6488 it != uniqueError.end(); ++it)
6489 {
6490 box_out((*it).c_str()); box_eol();
6491 }
6492 box_end(true);
6493 }
6494 }
6495 else // Cancel
6496 {
6497 Akey = a;
6498 Bkey = b;
6499 Skey = s;
6500 Lkey = l;
6501 Rkey = r;
6502 Pkey = p;
6503 Exkey1 = ex1;
6504 Exkey2 = ex2;
6505 Exkey3 = ex3;
6506 Exkey4 = ex4;
6507 DUkey = du;
6508 DDkey = dd;
6509 DLkey = dl;
6510 DRkey = dr;
6511 cheat_modifier_keys[0] = mod1a;
6512 cheat_modifier_keys[1] = mod1b;
6513 cheat_modifier_keys[2] = mod2a;
6514 cheat_modifier_keys[3] = mod2b;
6515
6516 done=true;
6517 }
6518
6519 rest(1);
6520 }
6521
6522 return D_O_K;
6523 }
6524
6525 int32_t onGamepad()
6526 {
6527 if (al_get_num_joysticks() == 0)
6528 {
6529 InfoDialog("ZC", "No gamepads detected.").show();
6530 return D_O_K;
6531 }
6532
6533 int32_t a = Abtn;
6534 int32_t b = Bbtn;
6535 int32_t s = Sbtn;
6536 int32_t l = Lbtn;
6537 int32_t r = Rbtn;
6538 int32_t m = Mbtn;
6539 int32_t p = Pbtn;
6540 int32_t ex1 = Exbtn1;
6541 int32_t ex2 = Exbtn2;
6542 int32_t ex3 = Exbtn3;
6543 int32_t ex4 = Exbtn4;
6544 int32_t up = DUbtn;
6545 int32_t down = DDbtn;
6546 int32_t left = DLbtn;
6547 int32_t right = DRbtn;
6548 int32_t joy = joystick_index;
6549 int32_t stick_1 = js_stick_1_x_stick;
6550 int32_t stick_2 = js_stick_2_x_stick;
6551
6552 gamepad_dlg[0].dp2=get_zc_font(font_lfont);
6553 if(analog_movement)
6554 gamepad_dlg[56].flags|=D_SELECTED;
6555 else
6556 gamepad_dlg[56].flags&=~D_SELECTED;
6557
6558 // TODO: should use controller device GUID or name instead of index, otherwise this value is not
6559 // consistent unless exact same number of joysticks is always connected. Name is problematic b/c
6560 // xinput driver doesn't actually get a name (at least, doesn't for my Xbox controller).
6561 // TODO: should store gamepad control mappings per-controller, otherwise switching joystick
6562 // requires remapping every time.
6563 if (joystick_index >= al_get_num_joysticks())
6564 joystick_index = 0;
6565 gamepad_dlg[61].d2 = joystick_index;
6566
6567 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6568 if (!gamepad_dlg_cur_joystick)
6569 {
6570 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6571 return D_CLOSE;
6572 }
6573
6574 large_dialog(gamepad_dlg);
6575
6576 int32_t ret = do_zqdialog(gamepad_dlg,4);
6577
6578 if(ret == 4) //OK
6579 {
6580 analog_movement = gamepad_dlg[56].flags&D_SELECTED;
6581 joystick_index = gamepad_dlg[61].d2;
6582 gamepad_dlg_cur_joystick = al_get_joystick(joystick_index);
6583 if (!gamepad_dlg_cur_joystick)
6584 {
6585 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
6586 return D_CLOSE;
6587 }
6588 js_stick_1_y_stick = js_stick_1_x_stick;
6589 js_stick_2_y_stick = js_stick_2_x_stick;
6590 save_control_configs(false);
6591 }
6592 else //Cancel
6593 {
6594 Abtn = a;
6595 Bbtn = b;
6596 Sbtn = s;
6597 Lbtn = l;
6598 Rbtn = r;
6599 Mbtn = m;
6600 Pbtn = p;
6601 Exbtn1 = ex1;
6602 Exbtn2 = ex2;
6603 Exbtn3 = ex3;
6604 Exbtn4 = ex4;
6605 DUbtn = up;
6606 DDbtn = down;
6607 DLbtn = left;
6608 DRbtn = right;
6609 joystick_index = joy;
6610 js_stick_1_x_stick = stick_1;
6611 js_stick_2_x_stick = stick_2;
6612 }
6613
6614 return D_O_K;
6615 }
6616
6617 int32_t onCheatKeys()
6618 {
6619 int32_t oldcheats[Cheat::Last][2];
6620 memcpy(oldcheats, cheatkeys, sizeof(cheatkeys));
6621
6622 bool done=false;
6623
6624 while(!done)
6625 {
6626 bool confirm = false;
6627 CheatKeysDialog(&confirm).show();
6628 if(confirm) // OK
6629 {
6630 std::vector<std::string> uniqueError;
6631 char buf[512];
6632 for(size_t q = 1; q < Cheat::Last; ++q)
6633 {
6634 if(cheatkeys[q][1] && !cheatkeys[q][0])
6635 {
6636 cheatkeys[q][0] = cheatkeys[q][1];
6637 cheatkeys[q][1] = 0;
6638 }
6639 }
6640 for(size_t q = 1; q < Cheat::Last; ++q)
6641 {
6642 if(!bindable_cheat((Cheat)q)) continue;
6643 for(size_t p = q+1; p < Cheat::Last; ++p)
6644 {
6645 if(!bindable_cheat((Cheat)p)) continue;
6646 for(size_t q2 = 0; q2 <= 1; ++q2)
6647 for(size_t p2 = 0; p2 <= 1; ++p2)
6648 {
6649 if(cheatkeys[q][q2] == cheatkeys[p][p2] && cheatkeys[q][q2] != 0)
6650 {
6651 uniqueError.push_back(fmt::format("'{}' ({}) conflicts with '{}' ({}) - both '{}'",
6652 cheat_to_string((Cheat)q), q2?"Alt":"Main",
6653 cheat_to_string((Cheat)p), p2?"Alt":"Main",
6654 get_keystr(cheatkeys[q][q2])));
6655 }
6656 }
6657 }
6658 }
6659 if(uniqueError.size() == 0)
6660 {
6661 done = true;
6662 save_cheatkeys();
6663 }
6664 else
6665 {
6666 box_start(1, "Duplicate Keys", get_zc_font(font_lfont), get_zc_font(font_sfont), false, 500,400, 2);
6667 box_out("Cannot have duplicate keybinds!"); box_eol();
6668 for(std::vector<std::string>::iterator it = uniqueError.begin();
6669 it != uniqueError.end(); ++it)
6670 {
6671 box_out((*it).c_str()); box_eol();
6672 }
6673 box_end(true);
6674 }
6675 }
6676 else // Cancel
6677 {
6678 memcpy(cheatkeys, oldcheats, sizeof(cheatkeys));
6679 done=true;
6680 }
6681 rest(1);
6682 }
6683
6684 return D_O_K;
6685 }
6686
6687 int32_t onSound()
6688 {
6689 if (get_qr(qr_OLD_SCRIPT_VOLUME))
6690 {
6691 if (FFCore.coreflags & FFCORE_SCRIPTED_MIDI_VOLUME)
6692 {
6693 master_volume(-1, ((int32_t)FFCore.usr_midi_volume));
6694 }
6695 if (FFCore.coreflags & FFCORE_SCRIPTED_DIGI_VOLUME)
6696 {
6697 master_volume((int32_t)(FFCore.usr_digi_volume), 1);
6698 }
6699 if (FFCore.coreflags & FFCORE_SCRIPTED_MUSIC_VOLUME)
6700 {
6701 emusic_volume = (int32_t)FFCore.usr_music_volume;
6702 }
6703 if (FFCore.coreflags & FFCORE_SCRIPTED_SFX_VOLUME)
6704 {
6705 sfx_volume = (int32_t)FFCore.usr_sfx_volume;
6706 }
6707 }
6708 if ( FFCore.coreflags&FFCORE_SCRIPTED_PANSTYLE )
6709 {
6710 pan_style = (int32_t)FFCore.usr_panstyle;
6711 }
6712
6713 int32_t m = midi_volume;
6714 int32_t e = emusic_volume;
6715 int32_t s = sfx_volume;
6716 int32_t p = pan_style;
6717 pan_style = vbound(pan_style,0,3);
6718
6719 sound_dlg[0].dp2=get_zc_font(font_lfont);
6720
6721 large_dialog(sound_dlg);
6722
6723 midi_dp[1] = sound_dlg[6].x;
6724 midi_dp[2] = sound_dlg[6].y;
6725 emus_dp[1] = sound_dlg[8].x;
6726 emus_dp[2] = sound_dlg[8].y;
6727 sfx_dp[1] = sound_dlg[10].x;
6728 sfx_dp[2] = sound_dlg[10].y;
6729 pan_dp[1] = sound_dlg[11].x;
6730 pan_dp[2] = sound_dlg[11].y;
6731 sound_dlg[15].d2 = (midi_volume==255) ? 32 : midi_volume>>3;
6732 sound_dlg[17].d2 = (emusic_volume==255) ? 32 : emusic_volume>>3;
6733 sound_dlg[19].d2 = (sfx_volume==255) ? 32 : sfx_volume>>3;
6734 sound_dlg[20].d2 = pan_style;
6735
6736 int32_t ret = do_zqdialog(sound_dlg,1);
6737
6738 if(ret==2)
6739 {
6740 master_volume(digi_volume,midi_volume);
6741 if (zcmusic)
6742 zcmusic_set_volume(zcmusic, emusic_volume);
6743
6744 int32_t temp_volume = sfx_volume;
6745 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
6746 temp_volume = (sfx_volume * FFCore.usr_sfx_volume) / 10000 / 100;
6747 for(int32_t i=0; i<WAV_COUNT; ++i)
6748 {
6749 if(sfx_voice[i] >= 0)
6750 voice_set_volume(sfx_voice[i], temp_volume);
6751 }
6752 zc_set_config(sfx_sect,"midi",midi_volume);
6753 zc_set_config(sfx_sect,"sfx",sfx_volume);
6754 zc_set_config(sfx_sect,"emusic",emusic_volume);
6755 zc_set_config(sfx_sect,"pan",pan_style);
6756 }
6757 else
6758 {
6759 midi_volume = m;
6760 emusic_volume = e;
6761 sfx_volume = s;
6762 pan_style = p;
6763 }
6764
6765 return D_O_K;
6766 }
6767
6768 int32_t queding(char const* s1, char const* s2, char const* s3)
6769 {
6770 return jwin_alert("ZQuest Classic",s1,s2,s3,"&Yes","&No",'y','n',get_zc_font(font_lfont));
6771 }
6772
6773 int32_t onQuit()
6774 {
6775 if(Playing)
6776 {
6777 int32_t ret=0;
6778
6779 if(get_qr(qr_NOCONTINUE))
6780 {
6781 if(standalone_mode)
6782 {
6783 ret=queding("End current game?",
6784 "The continue screen is disabled; the game",
6785 "will be reloaded from the last save.");
6786 }
6787 else
6788 {
6789 ret=queding("End current game?",
6790 "The continue screen is disabled. You will",
6791 "be returned to the file select screen.");
6792 }
6793 }
6794 else
6795 ret=queding("End current game?",NULL,NULL);
6796
6797 if(ret==1)
6798 {
6799 disableClickToFreeze=false;
6800 Quit=qQUIT;
6801
6802 // Trying to evade a door repair charge?
6803 if(repaircharge)
6804 {
6805 game->change_drupy(-repaircharge);
6806 repaircharge=0;
6807 }
6808
6809 return D_CLOSE;
6810 }
6811 }
6812
6813 return D_O_K;
6814 }
6815
6816 int32_t onTryQuitMenu()
6817 {
6818 return onTryQuit(true);
6819 }
6820
6821 int32_t onTryQuit(bool inMenu)
6822 {
6823 if(Playing && !(GameFlags & GAMEFLAG_NO_F6))
6824 {
6825 if(active_cutscene.can_f6())
6826 {
6827 if(get_qr(qr_OLD_F6))
6828 {
6829 if(inMenu) onQuit();
6830 else /*if(!get_qr(qr_NOCONTINUE))*/ f_Quit(qQUIT);
6831 }
6832 else
6833 {
6834 disableClickToFreeze=false;
6835 GameFlags |= GAMEFLAG_TRYQUIT;
6836 }
6837 return D_CLOSE;
6838 }
6839 else active_cutscene.error();
6840 }
6841
6842 return D_O_K;
6843 }
6844
6845 int32_t onReset()
6846 {
6847 if(queding(" Reset system? ",NULL,NULL)==1)
6848 {
6849 disableClickToFreeze=false;
6850 Quit=qRESET;
6851 replay_quit();
6852 return D_CLOSE;
6853 }
6854
6855 return D_O_K;
6856 }
6857
6858 int32_t onExit()
6859 {
6860 if(queding(" Quit ZQuest Classic? ",NULL,NULL)==1)
6861 {
6862 Quit=qEXIT;
6863 return D_CLOSE;
6864 }
6865
6866 return D_O_K;
6867 }
6868
6869 int32_t onDebug()
6870 {
6871 if(debug_enabled)
6872 set_debug(!get_debug());
6873 return D_O_K;
6874 }
6875
6876 int32_t onHeartBeep()
6877 {
6878 heart_beep=!heart_beep;
6879 zc_set_config(cfg_sect,"heart_beep",heart_beep);
6880 return D_O_K;
6881 }
6882
6883 int32_t onSaveIndicator()
6884 {
6885 use_save_indicator = use_save_indicator ? 0 : 1;
6886 zc_set_config(cfg_sect,"save_indicator",use_save_indicator);
6887 return D_O_K;
6888 }
6889
6890 int32_t onEpilepsy()
6891 {
6892 if(jwin_alert3(
6893 "Epilepsy Flash Reduction",
6894 "Enabling this will reduce the intensity of flashing and screen wave effects.",
6895 "Disabling this will restore standard flash and wavy behaviour.",
6896 "Proceed?",
6897 "&Yes",
6898 "&No",
6899 NULL,
6900 'y',
6901 'n',
6902 0,
6903 get_zc_font(font_lfont)) == 1)
6904 {
6905 epilepsyFlashReduction = epilepsyFlashReduction ? 0 : 1;
6906 zc_set_config(cfg_sect,"epilepsy_flash_reduction",epilepsyFlashReduction);
6907 }
6908 return D_O_K;
6909 }
6910
6911 bool rc = false;
6912
6913 static DIALOG getnum_dlg[] =
6914 {
6915 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
6916 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
6917 { jwin_text_proc, 104, 104+4, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Number:", NULL, NULL },
6918 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
6919 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
6920 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
6921 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
6922 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
6923 };
6924
6925 int32_t getnumber(const char *prompt,int32_t initialval)
6926 {
6927 char buf[20];
6928 sprintf(buf,"%d",initialval);
6929 getnum_dlg[0].dp=(void *)prompt;
6930 getnum_dlg[0].dp2=get_zc_font(font_lfont);
6931 getnum_dlg[2].dp=buf;
6932
6933 large_dialog(getnum_dlg);
6934
6935 if(do_zqdialog(getnum_dlg,2)==3)
6936 return atoi(buf);
6937
6938 return initialval;
6939 }
6940
6941 int32_t onLife()
6942 {
6943 int value = vbound(getnumber("Life",game->get_life()),1,game->get_maxlife());
6944 cheats_enqueue(Cheat::Life, value);
6945 return D_O_K;
6946 }
6947
6948 int32_t onHeartC()
6949 {
6950 int max_life = vbound(getnumber("Heart Containers",game->get_maxlife()/game->get_hp_per_heart()),1,4095) * game->get_hp_per_heart();
6951 int life = vbound(getnumber("Life",game->get_life()/game->get_hp_per_heart()),1,max_life/game->get_hp_per_heart())*game->get_hp_per_heart();
6952 cheats_enqueue(Cheat::MaxLife, max_life);
6953 cheats_enqueue(Cheat::Life, life);
6954 return D_O_K;
6955 }
6956
6957 int32_t onMagicC()
6958 {
6959 int max_magic = vbound(getnumber("Magic Containers",game->get_maxmagic()/game->get_mp_per_block()),0,2047) * game->get_mp_per_block();
6960 int magic = vbound(getnumber("Magic",game->get_magic()/game->get_mp_per_block()),0,max_magic/game->get_mp_per_block())*game->get_mp_per_block();
6961 cheats_enqueue(Cheat::MaxMagic, max_magic);
6962 cheats_enqueue(Cheat::Magic, magic);
6963 return D_O_K;
6964 }
6965
6966 int32_t onRupies()
6967 {
6968 int value = vbound(getnumber("Rupees",game->get_rupies()),0,game->get_maxcounter(1));
6969 cheats_enqueue(Cheat::Rupies, value);
6970 return D_O_K;
6971 }
6972
6973 int32_t onMaxBombs()
6974 {
6975 int value = vbound(getnumber("Max Bombs",game->get_maxbombs()),0,0xFFFF);
6976 cheats_enqueue(Cheat::MaxBombs, value);
6977 cheats_enqueue(Cheat::Bombs, value);
6978 return D_O_K;
6979 }
6980
6981 int32_t onRefillLife()
6982 {
6983 cheats_enqueue(Cheat::Life, game->get_maxlife());
6984 return D_O_K;
6985 }
6986 int32_t onRefillMagic()
6987 {
6988 cheats_enqueue(Cheat::Magic, game->get_maxmagic());
6989 return D_O_K;
6990 }
6991 int32_t onClock()
6992 {
6993 cheats_enqueue(Cheat::Clock);
6994 return D_O_K;
6995 }
6996
6997 int32_t onQstPath()
6998 {
6999 char initial_path[2048];
7000 chop_path(qstdir);
7001 strcpy(initial_path, qstdir);
7002
7003 if (auto result = prompt_for_existing_folder("Quest File Directory", initial_path, "qst"))
7004 {
7005 char* path = result->data();
7006 chop_path(path);
7007 fix_filename_case(path);
7008 fix_filename_slashes(path);
7009 strcpy(qstdir,path);
7010 strcpy(qstpath,qstdir);
7011 zc_set_config("zeldadx","quest_dir",qstdir);
7012 flush_config_file();
7013 }
7014
7015 return D_O_K;
7016 }
7017
7018 #include "dialog/cheat_dialog.h"
7019 int32_t onCheat()
7020 {
7021 call_setcheat_dialog();
7022 game->set_cheat(maxcheat);
7023 if(cheat) game->did_cheat(true);
7024 return D_O_K;
7025 }
7026
7027 int32_t onCheatRupies()
7028 {
7029 cheats_enqueue(Cheat::Rupies, game->get_maxcounter(1));
7030 return D_O_K;
7031 }
7032
7033 int32_t onCheatArrows()
7034 {
7035 cheats_enqueue(Cheat::Arrows, game->get_maxarrows());
7036 return D_O_K;
7037 }
7038
7039 int32_t onCheatBombs()
7040 {
7041 cheats_enqueue(Cheat::Bombs, game->get_maxbombs(), game->get_maxcounter(6));
7042 return D_O_K;
7043 }
7044
7045 // *** screen saver
7046
7047 18519801 int32_t after_time()
7048 {
7049
1/2
✓ Branch 0 taken 18519801 times.
✗ Branch 1 not taken.
18519801 if(ss_enable == 0)
7050 return INT_MAX;
7051
7052
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(ss_after <= 0)
7053 return 5 * 60;
7054
7055
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(ss_after <= 3)
7056 return ss_after * 15 * 60;
7057
7058
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519801 times.
18519801 if(ss_after <= 13)
7059 return (ss_after - 3) * 60 * 60;
7060
7061 18519801 return MAX_IDLE + 1;
7062 18519801 }
7063
7064 static const char *after_str[15] =
7065 {
7066 " 5 sec", "15 sec", "30 sec", "45 sec", " 1 min", " 2 min", " 3 min",
7067 " 4 min", " 5 min", " 6 min", " 7 min", " 8 min", " 9 min", "10 min",
7068 "Never"
7069 };
7070
7071 const char *after_list(int32_t index, int32_t *list_size)
7072 {
7073 if(index < 0)
7074 {
7075 *list_size = 15;
7076 return NULL;
7077 }
7078
7079 return after_str[index];
7080 }
7081
7082 414 static ListData after__list(after_list, &font);
7083
7084 static DIALOG scrsaver_dlg[] =
7085 {
7086 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
7087 414 { jwin_win_proc, 32, 64, 256, 136, 0, 0, 0, D_EXIT, 0, 0, (void *) "Screen Saver Settings", NULL, NULL },
7088 414 { jwin_frame_proc, 42, 92, 236, 70, 0, 0, 0, 0, FR_ETCHED,0, NULL, NULL, NULL },
7089 414 { jwin_text_proc, 60, 104, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Run After", NULL, NULL },
7090 414 { jwin_text_proc, 60, 128, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Speed", NULL, NULL },
7091 414 { jwin_text_proc, 60, 144, 48, 8, vc(0), vc(11), 0, 0, 0, 0, (void *) "Density", NULL, NULL },
7092 414 { jwin_droplist_proc, 144, 100, 96, 16, 0, 0, 0, 0, 0, 0, (void *) &after__list, NULL, NULL },
7093 414 { jwin_slider_proc, 144, 128, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7094 414 { jwin_slider_proc, 144, 144, 116, 8, vc(0), jwin_pal[jcBOX], 0, 0, 6, 0, NULL, NULL, NULL },
7095 414 { jwin_button_proc, 42, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
7096 414 { jwin_button_proc, 124, 170, 72, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Preview", NULL, NULL },
7097 414 { jwin_button_proc, 218, 170, 61, 21, 0, 0, 0, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
7098 414 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
7099 414 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
7100 };
7101
7102 int32_t onScreenSaver()
7103 {
7104 scrsaver_dlg[0].dp2=get_zc_font(font_lfont);
7105 int32_t oldcfgs[3];
7106 scrsaver_dlg[5].d1 = scrsaver_dlg[5].d2 = oldcfgs[0] = ss_after;
7107 scrsaver_dlg[6].d2 = oldcfgs[1] = ss_speed;
7108 scrsaver_dlg[7].d2 = oldcfgs[2] = ss_density;
7109
7110 large_dialog(scrsaver_dlg);
7111
7112 int32_t ret = do_zqdialog(scrsaver_dlg,-1);
7113
7114 if(ret == 8 || ret == 9)
7115 {
7116 ss_after = scrsaver_dlg[5].d1;
7117 ss_speed = scrsaver_dlg[6].d2;
7118 ss_density = scrsaver_dlg[7].d2;
7119 if(oldcfgs[0] != ss_after)
7120 zc_set_config(cfg_sect,"ss_after",ss_after);
7121 if(oldcfgs[1] != ss_speed)
7122 zc_set_config(cfg_sect,"ss_speed",ss_speed);
7123 if(oldcfgs[2] != ss_density)
7124 zc_set_config(cfg_sect,"ss_density",ss_density);
7125 }
7126
7127 if(ret == 9)
7128 // preview Screen Saver
7129 {
7130 clear_keybuf();
7131 Matrix(ss_speed, ss_density, 30);
7132 system_pal(true);
7133 sys_mouse();
7134 }
7135
7136 return D_O_K;
7137 }
7138
7139 /***** Menus *****/
7140
7141 enum
7142 {
7143 MENUID_GAME_LOADQUEST,
7144 MENUID_GAME_ENDGAME,
7145 };
7146
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu game_menu
7147 3312 {
7148
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Continue","ESC", onContinue },
7149
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7150
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "L&oad Quest...", onCustomGame, MENUID_GAME_LOADQUEST },
7151
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&End Game","F6", onTryQuitMenu, MENUID_GAME_ENDGAME },
7152
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7153 #ifdef __EMSCRIPTEN__
7154 { "&Reset","F7", onReset },
7155 #elif defined(ALLEGRO_MACOSX)
7156 { "&Reset","F7", onReset },
7157 { "&Quit","F8", onExit },
7158 #else
7159
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Reset","F9", onReset },
7160
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Quit","F10", onExit },
7161 #endif
7162 };
7163
7164
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu snapshot_format_menu
7165 2898 {
7166
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&BMP", std::bind(onSetSnapshotFormat, ssfmtBMP) },
7167
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&GIF", std::bind(onSetSnapshotFormat, ssfmtGIF) },
7168
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&JPG", std::bind(onSetSnapshotFormat, ssfmtJPG) },
7169
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&PNG", std::bind(onSetSnapshotFormat, ssfmtPNG) },
7170
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "PC&X", std::bind(onSetSnapshotFormat, ssfmtPCX) },
7171
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&TGA", std::bind(onSetSnapshotFormat, ssfmtTGA) },
7172 };
7173
7174
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu bottom_8_pixels_menu
7175 1656 {
7176
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&Default (qst)", std::bind(onSetBottom8Pixels, 0) },
7177
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&On", std::bind(onSetBottom8Pixels, 1) },
7178
4/8
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 414 times.
✗ Branch 7 not taken.
414 { "&Off", std::bind(onSetBottom8Pixels, 2) },
7179 };
7180
7181
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu controls_menu
7182 1656 {
7183
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Key&board...", onKeyboard },
7184
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Gamepad...", onGamepad },
7185
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Cheat Keys...", onCheatKeys },
7186 };
7187
7188
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu name_entry_mode_menu
7189 1656 {
7190
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Keyboard", onKeyboardEntry },
7191
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Letter Grid", onLetterGridEntry },
7192
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Extended Letter Grid", onExtLetterGridEntry },
7193 };
7194
7195 static void set_controls_menu_active()
7196 {
7197
7198 }
7199
7200 enum
7201 {
7202 MENUID_WINDOW_LOCK_ASPECT,
7203 MENUID_WINDOW_LOCK_INTSCALE,
7204 MENUID_WINDOW_SAVE_SIZE,
7205 MENUID_WINDOW_SAVE_POS,
7206 MENUID_WINDOW_STRETCH,
7207 };
7208
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu window_menu
7209 2484 {
7210
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Lock Aspect Ratio", onDragAspect, MENUID_WINDOW_LOCK_ASPECT },
7211
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Lock Integer Scale", onIntegerScaling, MENUID_WINDOW_LOCK_INTSCALE },
7212
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save Size Changes", onSaveDragResize, MENUID_WINDOW_SAVE_SIZE },
7213
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save Position Changes", onWinPosSave, MENUID_WINDOW_SAVE_POS },
7214
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Stretch Game Area", onStretchGame, MENUID_WINDOW_STRETCH },
7215 };
7216 void call_zc_options_dlg();
7217 enum
7218 {
7219 MENUID_OPTIONS_PAUSE_BG,
7220 MENUID_OPTIONS_EPILEPSYPROT,
7221 MENUID_OPTIONS_SHOWBOTTOMPIXELS,
7222 };
7223
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu options_menu
7224 3312 {
7225
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Name &Entry Mode", &name_entry_mode_menu },
7226
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "S&napshot Format", &snapshot_format_menu },
7227
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Window Settings", &window_menu },
7228
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Epilepsy Flash Reduction", onEpilepsy, MENUID_OPTIONS_EPILEPSYPROT },
7229
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Pause In Background", onPauseInBackground, MENUID_OPTIONS_PAUSE_BG },
7230
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show Bottom 8 Pixels", &bottom_8_pixels_menu, MENUID_OPTIONS_SHOWBOTTOMPIXELS },
7231
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "More Options", call_zc_options_dlg },
7232 };
7233 enum
7234 {
7235 MENUID_SETTINGS_CONTROLS,
7236 MENUID_SETTINGS_CAPFPS,
7237 MENUID_SETTINGS_SHOWFPS,
7238 MENUID_SETTINGS_SHOWTIME,
7239 MENUID_SETTINGS_CLICK_FREEZE,
7240 MENUID_SETTINGS_TRANSLAYERS,
7241 MENUID_SETTINGS_NESQUIT,
7242 MENUID_SETTINGS_VOLKEYS,
7243 MENUID_SETTINGS_HEARTBEEP,
7244 MENUID_SETTINGS_SAVEINDICATOR,
7245 MENUID_SETTINGS_DEBUG,
7246 };
7247
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu settings_menu
7248 7038 {
7249
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Sound...", onSound },
7250
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "C&ontrols", &controls_menu, MENUID_SETTINGS_CONTROLS },
7251
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7252
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Options", &options_menu },
7253
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7254
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "&Cap FPS","F1", onThrottleFPS, MENUID_SETTINGS_CAPFPS },
7255
3/6
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 414 times.
✗ Branch 5 not taken.
414 { "Show &FPS","F2", onShowFPS, MENUID_SETTINGS_SHOWFPS },
7256
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show &Time", onShowTime, MENUID_SETTINGS_SHOWTIME },
7257
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Click to Freeze", onClickToFreeze, MENUID_SETTINGS_CLICK_FREEZE },
7258
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Cont. &Heart Beep", onHeartBeep, MENUID_SETTINGS_HEARTBEEP },
7259
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show Trans. &Layers", onTransLayers, MENUID_SETTINGS_TRANSLAYERS },
7260
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Up+A+B To &Quit", onNESquit, MENUID_SETTINGS_NESQUIT },
7261
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Volume &Keys", onVolKeys, MENUID_SETTINGS_VOLKEYS },
7262
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Sa&ve Indicator", onSaveIndicator, MENUID_SETTINGS_SAVEINDICATOR },
7263
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7264
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Debu&g", onDebug, MENUID_SETTINGS_DEBUG },
7265 };
7266
7267 enum
7268 {
7269 MENUID_MISC_FULLSCREEN,
7270 MENUID_MISC_VIDMODE,
7271 MENUID_MISC_QUEST_INFO,
7272 MENUID_MISC_QUEST_DIR,
7273 MENUID_MISC_CONSOLE,
7274 MENUID_MISC_CLEAR_CONSOLE_ON_LOAD,
7275 };
7276
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu misc_menu
7277 6210 {
7278
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&About...", onAbout },
7279 // TODO: re-enable, but: 1) do not use a bitmap thing that is hard to update 2) update names and 3) don't use the Z-word.
7280 // { "&Credits...", onCredits },
7281
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Fullscreen", onFullscreenMenu, MENUID_MISC_FULLSCREEN },
7282
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Video Mode...", onVidMode, MENUID_MISC_VIDMODE },
7283
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7284
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Quest Info...", onQuest, MENUID_MISC_QUEST_INFO },
7285
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Quest &MIDI Info...", onMIDICredits },
7286
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Quest &Directory...", onQstPath, MENUID_MISC_QUEST_DIR },
7287
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7288
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Take &Snapshot F12", onSnapshot },
7289
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Sc&reen Saver...", onScreenSaver },
7290
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Save ZC Configuration", OnSaveZCConfig },
7291
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show Console", onConsole, MENUID_MISC_CONSOLE },
7292
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Clear Console on Qst Load", onClrConsoleOnLoad, MENUID_MISC_CLEAR_CONSOLE_ON_LOAD },
7293
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Clear Directory Cache", OnnClearQuestDir },
7294 };
7295
7296 enum
7297 {
7298 MENUID_REFILL_ARROWS,
7299 };
7300
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu refill_menu
7301 2484 {
7302
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Life", onRefillLife },
7303
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Magic", onRefillMagic },
7304
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Bombs", onCheatBombs },
7305
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Rupees", onCheatRupies },
7306
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Arrows", onCheatArrows, MENUID_REFILL_ARROWS },
7307 };
7308
7309 enum
7310 {
7311 MENUID_SHOW_L0,
7312 MENUID_SHOW_L1,
7313 MENUID_SHOW_L2,
7314 MENUID_SHOW_L3,
7315 MENUID_SHOW_L4,
7316 MENUID_SHOW_L5,
7317 MENUID_SHOW_L6,
7318 MENUID_SHOW_OVER,
7319 MENUID_SHOW_PUSH,
7320 MENUID_SHOW_FFC,
7321 MENUID_SHOW_SPR,
7322 MENUID_SHOW_SCRIPTNAME,
7323 MENUID_SHOW_SOLIDITY,
7324 MENUID_SHOW_HITBOX,
7325 MENUID_SHOW_EFFECT,
7326 };
7327
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu show_menu
7328 7866 {
7329
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Combos", onShowLayer0, MENUID_SHOW_L0 },
7330
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 1", onShowLayer1, MENUID_SHOW_L1 },
7331
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 2", onShowLayer2, MENUID_SHOW_L2 },
7332
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 3", onShowLayer3, MENUID_SHOW_L3 },
7333
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 4", onShowLayer4, MENUID_SHOW_L4 },
7334
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 5", onShowLayer5, MENUID_SHOW_L5 },
7335
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Layer 6", onShowLayer6, MENUID_SHOW_L6 },
7336
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Overhead Combos", onShowLayerO, MENUID_SHOW_OVER },
7337
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Push Blocks", onShowLayerP, MENUID_SHOW_PUSH },
7338
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Freeform Combos", onShowLayerF, MENUID_SHOW_FFC },
7339
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Sprites", onShowLayerS, MENUID_SHOW_SPR },
7340
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7341
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Current FFC Scripts", onShowFFScripts, MENUID_SHOW_SCRIPTNAME },
7342
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 {},
7343
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Walkability", onShowLayerW, MENUID_SHOW_SOLIDITY },
7344
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Hitboxes", onShowHitboxes, MENUID_SHOW_HITBOX },
7345
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Effects", onShowLayerE, MENUID_SHOW_EFFECT },
7346
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Info Opacity", onShowInfoOpacity },
7347 };
7348
7349 enum
7350 {
7351 MENUID_CHEAT_CHOP_L1,
7352 MENUID_CHEAT_CHOP_L2,
7353 MENUID_CHEAT_CHOP_L3,
7354 MENUID_CHEAT_CHOP_L4,
7355 MENUID_CHEAT_INVULN,
7356 MENUID_CHEAT_NOCLIP,
7357 MENUID_CHEAT_IGNORESV,
7358 MENUID_CHEAT_GOFAST,
7359 };
7360
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 static NewMenu cheat_menu
7361 7038 {
7362
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Set &Cheat", onCheat },
7363
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L1 },
7364
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Re&fill", &refill_menu },
7365
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L2 },
7366
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Invincible", onClock, MENUID_CHEAT_INVULN },
7367
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Ma&x Bombs...", onMaxBombs },
7368
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Heart Containers...", onHeartC },
7369
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Magic Containers...", onMagicC },
7370
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L3 },
7371
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Hero Data...", onCheatConsole },
7372
1/2
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
414 { MENUID_CHEAT_CHOP_L4 },
7373
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Walk Through &Walls", onNoWalls, MENUID_CHEAT_NOCLIP },
7374
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Hero Ignores Side&view", onIgnoreSideview, MENUID_CHEAT_IGNORESV },
7375
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Quick Movement", onGoFast, MENUID_CHEAT_GOFAST },
7376
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Kill All Enemies", onKillCheat },
7377
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Trigger &Secrets", onSecretsCheat },
7378
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Trigger Secrets Perm", onSecretsCheatPerm },
7379
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Show/Hide Layer", &show_menu },
7380
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "Toggle &Light", onLightSwitch },
7381
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Goto Location...", onGoTo },
7382 };
7383
7384 #if DEVLEVEL > 0
7385 int32_t devLogging();
7386 int32_t devDebug();
7387 int32_t devTimestmp();
7388 #if DEVLEVEL > 1
7389 int32_t setCheat();
7390 #endif //DEVLEVEL > 1
7391 enum
7392 {
7393 MENUID_DEV_LOGGING,
7394 MENUID_DEV_DEBUG,
7395 MENUID_DEV_TIMESTAMP,
7396 MENUID_DEV_SETCHEAT,
7397 };
7398 static NewMenu dev_menu
7399 {
7400 { "&Force Error Log", devLogging, MENUID_DEV_LOGGING },
7401 // { "&Extra Debug Log", devDebug, MENUID_DEV_DEBUG },
7402 { "&Timestamp Log", devTimestmp, MENUID_DEV_TIMESTAMP },
7403 #if DEVLEVEL > 1
7404 {},
7405 { "Set &Cheat", setCheat, MENUID_DEV_SETCHEAT },
7406 #endif //DEVLEVEL > 1
7407 };
7408 int32_t devLogging()
7409 {
7410 dev_logging = !dev_logging;
7411 dev_menu.select_uid(MENUID_DEV_LOGGING, dev_logging);
7412 return D_O_K;
7413 }
7414 // int32_t devDebug()
7415 // {
7416 // dev_debug = !dev_debug;
7417 // dev_menu.select_uid(MENUID_DEV_DEBUG, dev_debug);
7418 // dev_menu[dv_dbg].flags = dev_debug ? D_SELECTED : 0;
7419 // return D_O_K;
7420 // }
7421 int32_t devTimestmp()
7422 {
7423 dev_timestmp = !dev_timestmp;
7424 dev_menu.select_uid(MENUID_DEV_TIMESTAMP, dev_timestmp);
7425 return D_O_K;
7426 }
7427 #if DEVLEVEL > 1
7428 int32_t setCheat()
7429 {
7430 cheat = (vbound(getnumber("Cheat Level",cheat), 0, 4));
7431 return D_O_K;
7432 }
7433 #endif //DEVLEVEL > 1
7434 #endif //DEVLEVEL > 0
7435
7436 enum
7437 {
7438 MENUID_PLAYER_CHEAT,
7439 };
7440
1/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
414 TopMenu the_player_menu
7441 2484 {
7442
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Game", &game_menu },
7443
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Settings", &settings_menu },
7444
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Cheat", &cheat_menu, MENUID_PLAYER_CHEAT, true },
7445
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&Replay", &replay_menu },
7446
2/4
✓ Branch 0 taken 414 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 414 times.
✗ Branch 3 not taken.
414 { "&ZC", &misc_menu },
7447 #if DEVLEVEL > 0
7448 { "&Dev", &dev_menu },
7449 #endif
7450 };
7451
7452 int32_t onPauseInBackground()
7453 {
7454 if(jwin_alert3(
7455 "Toggle Pause In Background",
7456 "This action will change whether ZC Player pauses when the window loses focus.",
7457 "",
7458 "Proceed?",
7459 "&Yes",
7460 "&No",
7461 NULL,
7462 'y',
7463 'n',
7464 0,
7465 get_zc_font(font_lfont)) == 1)
7466 {
7467 pause_in_background = pause_in_background ? 0 : 1;
7468 zc_set_config("zeldadx","pause_in_background", pause_in_background);
7469 int switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7470 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7471 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7472 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7473 }
7474 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7475 return D_O_K;
7476 }
7477
7478 int32_t onKeyboardEntry()
7479 {
7480 NameEntryMode=0;
7481 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7482 return D_O_K;
7483 }
7484
7485 int32_t onLetterGridEntry()
7486 {
7487 NameEntryMode=1;
7488 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7489 return D_O_K;
7490 }
7491
7492 int32_t onExtLetterGridEntry()
7493 {
7494 NameEntryMode=2;
7495 zc_set_config(cfg_sect,"name_entry_mode",NameEntryMode);
7496 return D_O_K;
7497 }
7498
7499 static BITMAP* oldscreen;
7500 int32_t onFullscreenMenu()
7501 {
7502 PALETTE oldpal;
7503 get_palette(oldpal);
7504
7505 fullscreen = !fullscreen;
7506 all_toggle_fullscreen(fullscreen);
7507 zc_set_config("zeldadx","fullscreen",fullscreen);
7508
7509 zc_set_palette(oldpal);
7510 gui_mouse_focus=0;
7511 extern int32_t switch_type;
7512 switch_type = pause_in_background ? SWITCH_PAUSE : SWITCH_BACKGROUND;
7513 set_display_switch_mode(fullscreen?SWITCH_BACKAMNESIA:switch_type);
7514 set_display_switch_callback(SWITCH_OUT, switch_out_callback);
7515 set_display_switch_callback(SWITCH_IN, switch_in_callback);
7516 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7517 misc_menu.select_uid(MENUID_MISC_VIDMODE, isFullScreen());
7518
7519 return D_O_K;
7520 }
7521
7522 313 void fix_menu()
7523 {
7524
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 313 times.
313 if(!debug_enabled)
7525 313 settings_menu.chop_index = 13;
7526 313 }
7527
7528 int32_t onSetSnapshotFormat(SnapshotType format)
7529 {
7530 SnapshotFormat = format;
7531 zc_set_config("zeldadx", "snapshot_format", format);
7532 snapshot_format_menu.select_only_index(format);
7533 return D_O_K;
7534 }
7535
7536 int32_t onSetBottom8Pixels(int option)
7537 {
7538 ShowBottomPixels = option;
7539 zc_set_config("zeldadx", "bottom_8_px", option);
7540 bottom_8_pixels_menu.select_only_index(option);
7541
7542 int qr = qr_HIDE_BOTTOM_8_PIXELS;
7543 bool value = false;
7544 if (option == 0)
7545 value = get_bit(quest_rules, qr) != 0; // This is the original value, as set in the qst file (or via scripting).
7546 else if (option == 1)
7547 value = false;
7548 else if (option == 2)
7549 value = true;
7550 enqueue_qr_change(qr, value);
7551
7552 return D_O_K;
7553 }
7554
7555 2917 void updateShowBottomPixels()
7556 {
7557 // It's too tricky the allow modifying the screen height between opening and closing the
7558 // active subscreen.
7559
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 2891 times.
2917 if (subscreen_open)
7560 26 return;
7561
7562
1/2
✓ Branch 0 taken 2891 times.
✗ Branch 1 not taken.
2891 if (!GameLoaded)
7563 show_bottom_8px = false;
7564 else
7565 2891 show_bottom_8px = !get_qr(qr_HIDE_BOTTOM_8_PIXELS);
7566
7567 2891 int target_bitmap_height = show_bottom_8px ? 232 : 224;
7568
2/2
✓ Branch 0 taken 2786 times.
✓ Branch 1 taken 105 times.
2891 if (framebuf->h != target_bitmap_height)
7569 {
7570 105 BITMAP* new_framebuf = create_bitmap_ex(8, 256, target_bitmap_height);
7571 105 clear_bitmap(new_framebuf);
7572 105 blit(framebuf, new_framebuf, 0, 0, 0, 0, new_framebuf->w, new_framebuf->h);
7573
7574 105 destroy_bitmap(framebuf);
7575 105 destroy_bitmap(script_menu_buf);
7576 105 destroy_bitmap(f6_menu_buf);
7577 105 destroy_bitmap(darkscr_bmp);
7578 105 destroy_bitmap(darkscr_bmp_trans);
7579
7580 105 framebuf = new_framebuf;
7581 105 script_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7582 105 f6_menu_buf = create_bitmap_ex(8, 256, target_bitmap_height);
7583 105 darkscr_bmp = create_bitmap_ex(8, 256, target_bitmap_height);
7584 105 darkscr_bmp_trans = create_bitmap_ex(8, 256, target_bitmap_height);
7585
7586 105 rti_game.a4_bitmap = framebuf;
7587 105 rti_game.set_size(framebuf->w, framebuf->h);
7588 105 al_set_new_bitmap_flags(ALLEGRO_CONVERT_BITMAP);
7589 105 al_destroy_bitmap(rti_game.bitmap);
7590 105 rti_game.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7591 105 al_destroy_bitmap(rti_infolayer.bitmap);
7592 105 rti_infolayer.bitmap = create_a5_bitmap(framebuf->w, framebuf->h);
7593 105 rti_infolayer.set_size(framebuf->w, framebuf->h);
7594 105 }
7595 2917 }
7596
7597 void color_layer(RGB *src,RGB *dest,char r,char g,char b,char pos,int32_t from,int32_t to)
7598 {
7599 PALETTE tmp;
7600
7601 for(int32_t i=0; i<256; i++)
7602 {
7603 tmp[i].r=r;
7604 tmp[i].g=g;
7605 tmp[i].b=b;
7606 }
7607
7608 fade_interpolate(src,tmp,dest,pos,from,to);
7609 }
7610
7611 46 void system_pal(bool force)
7612 {
7613
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
46 if(is_sys_pal && !force) return;
7614 46 is_sys_pal = true;
7615 46 load_colorset(gui_colorset, syspal, jwin_a5_colors);
7616 46 hw_palette = &syspal;
7617 46 update_hw_pal = true;
7618 46 }
7619
7620 static uint32_t entered_sys_pal = 0;
7621 46 void enter_sys_pal()
7622 {
7623
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(is_sys_pal)
7624 {
7625 if(entered_sys_pal)
7626 ++entered_sys_pal;
7627 return;
7628 }
7629 46 sys_mouse();
7630 46 system_pal(true);
7631 46 ++entered_sys_pal;
7632 46 }
7633 46 void exit_sys_pal()
7634 {
7635
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(entered_sys_pal)
7636 {
7637
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 if(!--entered_sys_pal)
7638 {
7639 46 game_pal();
7640 46 game_mouse();
7641 46 }
7642 46 }
7643 46 }
7644
7645 void switch_out_callback()
7646 {
7647 if (pause_in_background && !MenuOpen)
7648 {
7649 System();
7650 }
7651 }
7652
7653 void switch_in_callback()
7654 {
7655 }
7656
7657 1158 void game_pal()
7658 {
7659 1158 is_sys_pal = false;
7660 1158 entered_sys_pal = 0;
7661 1158 hw_palette = &RAMpal;
7662 1158 update_hw_pal = true;
7663 1158 }
7664
7665 static char bar_str[] = "";
7666
7667 46 void music_pause()
7668 {
7669 //al_pause_duh(tmplayer);
7670 46 zcmusic_pause(zcmusic, ZCM_PAUSE);
7671
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(zcmixer->oldtrack)
7672 zcmusic_pause(zcmixer->oldtrack, ZCM_PAUSE);
7673 46 zc_midi_pause();
7674 46 }
7675
7676 void music_resume()
7677 {
7678 //al_resume_duh(tmplayer);
7679 zcmusic_pause(zcmusic, ZCM_RESUME);
7680 if (zcmixer->oldtrack)
7681 zcmusic_pause(zcmixer->oldtrack, ZCM_RESUME);
7682 zc_midi_resume();
7683 }
7684
7685 7920 void music_stop()
7686 {
7687 //al_stop_duh(tmplayer);
7688 //unload_duh(tmusic);
7689 //tmusic=NULL;
7690 //tmplayer=NULL;
7691 7920 zcmusic_stop(zcmusic);
7692 7920 zcmusic_unload_file(zcmusic);
7693
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 7920 times.
7920 if (zcmixer->oldtrack)
7694 {
7695 zcmusic_stop(zcmixer->oldtrack);
7696 zcmusic_unload_file(zcmixer->oldtrack);
7697 }
7698 7920 zcmixer->newtrack = NULL;
7699 7920 zc_stop_midi();
7700 7920 currmidi=-1;
7701 7920 }
7702
7703 bool reload_fonts = false;
7704 void System()
7705 {
7706 mouse_down = gui_mouse_b();
7707 music_pause();
7708 pause_all_sfx();
7709 MenuOpen = true;
7710 enter_sys_pal();
7711 // FONT *oldfont=font;
7712 // font=tfont;
7713
7714 misc_menu.select_uid(MENUID_MISC_FULLSCREEN, isFullScreen());
7715 misc_menu.disable_uid(MENUID_MISC_VIDMODE, isFullScreen());
7716
7717 #if DEVLEVEL > 1
7718 dev_menu.disable_uid(MENUID_DEV_SETCHEAT, !Playing);
7719 #endif
7720 game_menu.disable_uid(MENUID_GAME_LOADQUEST, get_unset_save_slot());
7721 game_menu.disable_uid(MENUID_GAME_ENDGAME, !Playing);
7722 misc_menu.disable_uid(MENUID_MISC_QUEST_INFO, !Playing);
7723 misc_menu.disable_uid(MENUID_MISC_QUEST_DIR, Playing);
7724 clear_keybuf();
7725
7726 clear_bitmap(menu_bmp);
7727 oldscreen = screen;
7728 screen = menu_bmp;
7729
7730 the_player_menu.reset_state();
7731 the_player_menu.position(0, 0);
7732
7733 bool running = true;
7734 bool esc = key[KEY_ESC] || cMbtn();
7735 bool autopop = esc;
7736 do
7737 {
7738 if(reload_fonts)
7739 {
7740 init_custom_fonts();
7741 clear_bitmap(menu_bmp);
7742 broadcast_dialog_message(MSG_DRAW, 0);
7743 reload_fonts = false;
7744 }
7745 if(handle_close_btn_quit())
7746 break;
7747
7748 //update submenus
7749 {
7750 settings_menu.disable_uid(MENUID_SETTINGS_CONTROLS, replay_is_replaying());
7751 settings_menu.select_uid(MENUID_SETTINGS_CAPFPS, Throttlefps);
7752 settings_menu.select_uid(MENUID_SETTINGS_SHOWFPS, ShowFPS);
7753 settings_menu.select_uid(MENUID_SETTINGS_SHOWTIME, ShowGameTime);
7754 settings_menu.select_uid(MENUID_SETTINGS_CLICK_FREEZE, ClickToFreeze);
7755 settings_menu.select_uid(MENUID_SETTINGS_TRANSLAYERS, TransLayers);
7756 settings_menu.select_uid(MENUID_SETTINGS_NESQUIT, NESquit);
7757 settings_menu.select_uid(MENUID_SETTINGS_VOLKEYS, volkeys);
7758
7759 window_menu.select_uid(MENUID_WINDOW_LOCK_ASPECT, DragAspect);
7760 window_menu.select_uid(MENUID_WINDOW_LOCK_INTSCALE, scaleForceInteger);
7761 window_menu.select_uid(MENUID_WINDOW_SAVE_SIZE, SaveDragResize);
7762 window_menu.select_uid(MENUID_WINDOW_SAVE_POS, SaveWinPos);
7763 window_menu.select_uid(MENUID_WINDOW_STRETCH, stretchGame);
7764
7765 options_menu.select_uid(MENUID_OPTIONS_EPILEPSYPROT, epilepsyFlashReduction);
7766 options_menu.select_uid(MENUID_OPTIONS_PAUSE_BG, pause_in_background);
7767 options_menu.disable_uid(MENUID_OPTIONS_SHOWBOTTOMPIXELS, replay_is_replaying());
7768
7769 name_entry_mode_menu.select_only_index(NameEntryMode);
7770
7771 misc_menu.select_uid(MENUID_MISC_CONSOLE, console_enabled);
7772 misc_menu.select_uid(MENUID_MISC_CLEAR_CONSOLE_ON_LOAD, clearConsoleOnLoad);
7773
7774 bool nocheat = (replay_is_replaying() || !Playing
7775 || (!maxcheat && !zcheats.flags && !get_debug() && DEVLEVEL < 2 && !zqtesting_mode && !devpwd()));
7776 the_player_menu.disable_uid(MENUID_PLAYER_CHEAT, nocheat);
7777 refill_menu.disable_uid(MENUID_REFILL_ARROWS, !get_qr(qr_TRUEARROWS));
7778 cheat_menu.chop_index.reset();
7779 if(cheat < 4)
7780 cheat_menu.chop_index = cheat_menu.ind_at(MENUID_CHEAT_CHOP_L1+cheat);
7781 cheat_menu.select_uid(MENUID_CHEAT_INVULN, getClock());
7782 cheat_menu.select_uid(MENUID_CHEAT_NOCLIP, walk_through_walls);
7783 cheat_menu.select_uid(MENUID_CHEAT_IGNORESV, ignoreSideview);
7784 cheat_menu.select_uid(MENUID_CHEAT_GOFAST, gofast);
7785
7786 show_menu.select_uid(MENUID_SHOW_L0, show_layers[0]);
7787 show_menu.select_uid(MENUID_SHOW_L1, show_layers[1]);
7788 show_menu.select_uid(MENUID_SHOW_L2, show_layers[2]);
7789 show_menu.select_uid(MENUID_SHOW_L3, show_layers[3]);
7790 show_menu.select_uid(MENUID_SHOW_L4, show_layers[4]);
7791 show_menu.select_uid(MENUID_SHOW_L5, show_layers[5]);
7792 show_menu.select_uid(MENUID_SHOW_L6, show_layers[6]);
7793 show_menu.select_uid(MENUID_SHOW_OVER, show_layer_over);
7794 show_menu.select_uid(MENUID_SHOW_PUSH, show_layer_push);
7795 show_menu.select_uid(MENUID_SHOW_SPR, show_sprites);
7796 show_menu.select_uid(MENUID_SHOW_FFC, show_ffcs);
7797 show_menu.select_uid(MENUID_SHOW_SOLIDITY, show_walkflags);
7798 show_menu.select_uid(MENUID_SHOW_SCRIPTNAME, show_ff_scripts);
7799 show_menu.select_uid(MENUID_SHOW_HITBOX, show_hitboxes);
7800 show_menu.select_uid(MENUID_SHOW_EFFECT, show_effectflags);
7801
7802 settings_menu.select_uid(MENUID_SETTINGS_HEARTBEEP, heart_beep);
7803 settings_menu.select_uid(MENUID_SETTINGS_SAVEINDICATOR, use_save_indicator);
7804
7805 replay_menu.by_uid(MENUID_REPLAY_STOP)->text = fmt::format("Stop {}",
7806 replay_get_mode() == ReplayMode::Record ? "recording" : "replaying");
7807
7808 replay_menu.select_uid(MENUID_REPLAY_RECORDNEW, zc_get_config("zeldadx", "replay_new_saves", false));
7809 #ifdef HAS_CURL
7810 replay_menu.select_uid(MENUID_REPLAY_AUTOUPLOAD, replay_upload_auto_enabled());
7811 #endif
7812 replay_menu.disable_uid(MENUID_REPLAY_STOP, !replay_is_active());
7813 replay_menu.disable_uid(MENUID_REPLAY_SAVE, replay_get_mode() != ReplayMode::Record);
7814 replay_menu.select_uid(MENUID_REPLAY_SNAP_ALL, replay_is_snapshot_all_frames());
7815
7816 snapshot_format_menu.select_only_index(SnapshotFormat);
7817 bottom_8_pixels_menu.select_only_index(ShowBottomPixels);
7818 }
7819
7820 if(debug_enabled)
7821 settings_menu.select_uid(MENUID_SETTINGS_DEBUG, get_debug());
7822
7823 if(autopop)
7824 clear_keybuf();
7825 the_player_menu.run(true);
7826 if(autopop)
7827 {
7828 the_player_menu.pop_sub(0, &the_player_menu);
7829 the_player_menu.draw(screen, the_player_menu.hovered_ind());
7830 autopop = false;
7831 update_hw_screen();
7832 }
7833
7834 update_hw_screen();
7835
7836 auto mb = gui_mouse_b();
7837 if(XOR(mb, mouse_down))
7838 {
7839 if(!the_player_menu.has_mouse())
7840 if(mb)
7841 break;
7842 mouse_down = mb;
7843 }
7844
7845 if(input_idle(true) > after_time())
7846 // run Screeen Saver
7847 {
7848 // Screen saver enabled for now.
7849 clear_keybuf();
7850 Matrix(ss_speed, ss_density, 0);
7851 system_pal(true);
7852 sys_mouse();
7853 }
7854
7855 poll_keyboard();
7856 if(esc)
7857 {
7858 if(!key[KEY_ESC])
7859 esc = false;
7860 }
7861
7862 if(keypressed() && !CHECK_ALT) //System hotkeys
7863 {
7864 auto c = peekkey();
7865 bool eatkey = true;
7866 switch(c>>8)
7867 {
7868 //Spare keys used by the menu
7869 case KEY_UP:
7870 case KEY_DOWN:
7871 case KEY_LEFT:
7872 case KEY_RIGHT:
7873 eatkey = false;
7874 break;
7875 case KEY_F1:
7876 onThrottleFPS();
7877 break;
7878 case KEY_F2:
7879 onShowFPS();
7880 break;
7881 case KEY_F6:
7882 onTryQuitMenu();
7883 break;
7884 #ifndef ALLEGRO_MACOSX
7885 case KEY_F9:
7886 onReset();
7887 break;
7888 case KEY_F10:
7889 onExit();
7890 break;
7891 #else
7892 case KEY_F7:
7893 onReset();
7894 break;
7895 case KEY_F8:
7896 onExit();
7897 break;
7898 #endif
7899 case KEY_F12:
7900 onSnapshot();
7901 break;
7902 case KEY_TAB:
7903 onDebug();
7904 break;
7905 case KEY_ESC:
7906 if(!esc)
7907 running = false;
7908 break;
7909 }
7910 if(eatkey)
7911 readkey();
7912 }
7913 if(Quit || (GameFlags & GAMEFLAG_TRYQUIT))
7914 break;
7915 }
7916 while(running);
7917
7918 screen = oldscreen;
7919
7920 mouse_down=gui_mouse_b();
7921 MenuOpen = false;
7922 if(Quit)
7923 {
7924 kill_sfx();
7925 music_stop();
7926 update_hw_screen();
7927 }
7928 else
7929 {
7930 music_resume();
7931 resume_all_sfx();
7932
7933 if(rc)
7934 ringcolor(false);
7935 }
7936 exit_sys_pal();
7937
7938 eat_buttons();
7939
7940 rc=false;
7941 clear_keybuf();
7942
7943 zc_init_apply_cheat_delta();
7944 }
7945
7946 313 void fix_dialogs()
7947 {
7948 313 jwin_center_dialog(about_dlg);
7949 313 jwin_center_dialog(gamepad_dlg);
7950 313 jwin_center_dialog(credits_dlg);
7951 313 jwin_center_dialog(gamemode_dlg);
7952 313 jwin_center_dialog(getnum_dlg);
7953 313 jwin_center_dialog(goto_dlg);
7954 313 jwin_center_dialog(keyboard_control_dlg);
7955 313 jwin_center_dialog(midi_dlg);
7956 313 jwin_center_dialog(quest_dlg);
7957 313 jwin_center_dialog(scrsaver_dlg);
7958 313 jwin_center_dialog(sound_dlg);
7959 313 jwin_center_dialog(triforce_dlg);
7960 313 }
7961
7962 4329 INLINE int32_t mixvol(int32_t v1,int32_t v2)
7963 {
7964
3/4
✓ Branch 0 taken 4329 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 4307 times.
✓ Branch 3 taken 22 times.
4329 return (zc_min(v1,255)*zc_min(v2,255)) >> 8;
7965 }
7966
7967 292 int32_t get_emusic_volume()
7968 {
7969 292 int32_t temp_volume = emusic_volume;
7970
2/4
✓ Branch 0 taken 292 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 292 times.
✗ Branch 3 not taken.
292 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
7971 temp_volume = (emusic_volume * FFCore.usr_music_volume) / 10000 / 100;
7972
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 292 times.
292 if (!zcmusic)
7973 292 return temp_volume;
7974 return (temp_volume * zcmusic->fadevolume) / 10000;
7975 292 }
7976
7977 int32_t get_zcmusicpos()
7978 {
7979 int32_t debugtracething = zcmusic_get_curpos(zcmusic);
7980 return debugtracething;
7981 return 0;
7982 }
7983
7984 void set_zcmusicpos(int32_t position)
7985 {
7986 zcmusic_set_curpos(zcmusic, position);
7987 }
7988
7989 void set_zcmusicspeed(int32_t speed)
7990 {
7991 zcmusic_set_speed(zcmusic, speed);
7992 }
7993
7994 int32_t get_zcmusiclen()
7995 {
7996 return zcmusic_get_length(zcmusic);
7997 }
7998
7999 3 void set_zcmusicloop(double start, double end)
8000 {
8001 3 zcmusic_set_loop(zcmusic, start, end);
8002 3 }
8003
8004 64164 void jukebox(int32_t index,int32_t loop)
8005 {
8006
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if (is_headless())
8007 64164 return;
8008
8009 music_stop();
8010
8011 if(index<0) index=MAXMIDIS-1;
8012
8013 if(index>=MAXMIDIS) index=0;
8014
8015 music_stop();
8016
8017 // Allegro's DIGMID driver (the one normally used on on Linux) gets
8018 // stuck notes when a song stops. This fixes it.
8019 if(strcmp(midi_driver->name, "DIGMID")==0)
8020 zc_set_volume(0, 0);
8021
8022 zc_set_volume(-1, mixvol(tunes[index].volume, midi_volume >>1));
8023 zc_play_midi(tunes[index].data,loop);
8024
8025 if(tunes[index].start>0)
8026 zc_midi_seek(tunes[index].start);
8027
8028 midi_loop_start = tunes[index].loop_start;
8029 midi_loop_end = tunes[index].loop_end;
8030
8031 currmidi=index;
8032 master_volume(digi_volume, midi_volume);
8033 //midi_paused=false;
8034 64164 }
8035
8036 64164 void jukebox(int32_t index)
8037 {
8038
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index<0) index=MAXMIDIS-1;
8039
8040
1/2
✓ Branch 0 taken 64164 times.
✗ Branch 1 not taken.
64164 if(index>=MAXMIDIS) index=0;
8041
8042 // do nothing if it's already playing
8043
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 64164 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
64164 if(index==currmidi && midi_pos>=0)
8044 {
8045 return;
8046 }
8047
8048 64164 jukebox(index,tunes[index].loop);
8049 64164 }
8050
8051 102 void play_DmapMusic()
8052 {
8053
1/2
✓ Branch 0 taken 102 times.
✗ Branch 1 not taken.
102 if (is_headless())
8054 102 return;
8055
8056 static char tfile[2048];
8057 static int32_t ttrack=0;
8058 bool domidi=false;
8059
8060 int32_t fadeoutframes = 0;
8061 if (zcmusic != NULL)
8062 fadeoutframes = zcmusic->fadeoutframes;
8063
8064 if(DMaps[cur_dmap].tmusic[0]!=0)
8065 {
8066 if(zcmusic==NULL ||
8067 strcmp(zcmusic->filename,DMaps[cur_dmap].tmusic)!=0 ||
8068 (zcmusic->type==ZCMF_GME && zcmusic->track != DMaps[cur_dmap].tmusictrack))
8069 {
8070 if (DMaps[cur_dmap].tmusic_xfade_in > 0 || fadeoutframes > 0)
8071 {
8072 if (play_enh_music_crossfade(DMaps[cur_dmap].tmusic, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes))
8073 {
8074 if (zcmusic != NULL)
8075 {
8076 zcmusic->fadeoutframes = DMaps[cur_dmap].tmusic_xfade_out;
8077 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8078 }
8079 }
8080 }
8081 else
8082 {
8083 if (zcmusic != NULL)
8084 {
8085 zcmusic_stop(zcmusic);
8086 zcmusic_unload_file(zcmusic);
8087 zcmusic = NULL;
8088 zcmixer->newtrack = NULL;
8089 }
8090
8091 zcmusic = zcmusic_load_for_quest(DMaps[cur_dmap].tmusic, qstpath).first;
8092 zcmixer->newtrack = zcmusic;
8093
8094 if (zcmusic != NULL)
8095 {
8096 zc_stop_midi();
8097 strcpy(tfile, DMaps[cur_dmap].tmusic);
8098 zcmusic_play(zcmusic, emusic_volume);
8099 int32_t temptracks = 0;
8100 temptracks = zcmusic_get_tracks(zcmusic);
8101 temptracks = (temptracks < 2) ? 1 : temptracks;
8102 ttrack = vbound(DMaps[cur_dmap].tmusictrack, 0, temptracks - 1);
8103 zcmusic_change_track(zcmusic, ttrack);
8104 zcmusic_set_loop(zcmusic, double(DMaps[cur_dmap].tmusic_loop_start / 10000.0), double(DMaps[cur_dmap].tmusic_loop_end / 10000.0));
8105 }
8106 else
8107 {
8108 tfile[0] = 0;
8109 domidi = true;
8110 }
8111 }
8112 }
8113 }
8114 else
8115 {
8116 if (DMaps[cur_dmap].midi == 0 && fadeoutframes > 0 && zcmusic != NULL && strcmp(zcmusic->filename, DMaps[cur_dmap].tmusic) != 0)
8117 {
8118 play_enh_music_crossfade(NULL, qstpath, DMaps[cur_dmap].tmusictrack, get_emusic_volume(), DMaps[cur_dmap].tmusic_xfade_in, fadeoutframes);
8119 }
8120 else
8121 {
8122 domidi = true;
8123 }
8124 }
8125
8126 if(domidi)
8127 {
8128 int32_t m=DMaps[cur_dmap].midi;
8129
8130 switch(m)
8131 {
8132 case 1:
8133 jukebox(ZC_MIDI_OVERWORLD);
8134 break;
8135
8136 case 2:
8137 jukebox(ZC_MIDI_DUNGEON);
8138 break;
8139
8140 case 3:
8141 jukebox(ZC_MIDI_LEVEL9);
8142 break;
8143
8144 default:
8145 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8146 jukebox(m+MIDIOFFSET_DMAP);
8147 else
8148 music_stop();
8149 }
8150 }
8151 102 }
8152
8153 35714 void playLevelMusic()
8154 {
8155
1/2
✓ Branch 0 taken 35714 times.
✗ Branch 1 not taken.
35714 if (is_headless())
8156 35714 return;
8157
8158 int32_t m=hero_scr->screen_midi;
8159
8160 switch(m)
8161 {
8162 case -2:
8163 music_stop();
8164 break;
8165
8166 case -1:
8167 play_DmapMusic();
8168 break;
8169
8170 case 1:
8171 jukebox(ZC_MIDI_OVERWORLD);
8172 break;
8173
8174 case 2:
8175 jukebox(ZC_MIDI_DUNGEON);
8176 break;
8177
8178 case 3:
8179 jukebox(ZC_MIDI_LEVEL9);
8180 break;
8181
8182 default:
8183 if(m>=4 && m<4+MAXCUSTOMMIDIS)
8184 jukebox(m+MIDIOFFSET_MAPSCR);
8185 else
8186 music_stop();
8187 }
8188 35714 }
8189
8190 4329 void master_volume(int32_t dv,int32_t mv)
8191 {
8192
7/8
✓ Branch 0 taken 2008 times.
✓ Branch 1 taken 2321 times.
✓ Branch 2 taken 1967 times.
✓ Branch 3 taken 354 times.
✓ Branch 4 taken 2321 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 1967 times.
✓ Branch 7 taken 354 times.
4329 if(dv>=0) digi_volume=zc_max(zc_min(dv,255),0);
8193
8194
7/8
✓ Branch 0 taken 2004 times.
✓ Branch 1 taken 2325 times.
✓ Branch 2 taken 2000 times.
✓ Branch 3 taken 325 times.
✓ Branch 4 taken 2325 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 2000 times.
✓ Branch 7 taken 325 times.
4329 if(mv>=0) midi_volume=zc_max(zc_min(mv,255),0);
8195
8196
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 4329 times.
✓ Branch 2 taken 4329 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4329 times.
4329 int32_t i = zc_min(zc_max(currmidi,0),MAXMIDIS-1);
8197 4329 int32_t temp_vol = midi_volume;
8198
2/2
✓ Branch 0 taken 4016 times.
✓ Branch 1 taken 313 times.
4329 if (!get_qr(qr_OLD_SCRIPT_VOLUME))
8199 313 temp_vol = (midi_volume * FFCore.usr_music_volume) / 10000 / 100;
8200 4329 zc_set_volume(digi_volume,mixvol(tunes[i].volume, temp_vol));
8201 4329 }
8202
8203 // array of voices, one for each sfx sample in the data file
8204 // 0+ = voice #
8205 // -1 = voice not allocated
8206 313 void Z_init_sound()
8207 {
8208
2/2
✓ Branch 0 taken 80128 times.
✓ Branch 1 taken 313 times.
80441 for(int32_t i=0; i<WAV_COUNT; i++)
8209 80128 sfx_voice[i]=-1;
8210
8211 313 const char* midis[ZC_MIDI_COUNT] = {
8212 "assets/dungeon.mid",
8213 "assets/ending.mid",
8214 "assets/gameover.mid",
8215 "assets/level9.mid",
8216 "assets/overworld.mid",
8217 "assets/title.mid",
8218 "assets/triforce.mid",
8219 };
8220
2/2
✓ Branch 0 taken 2191 times.
✓ Branch 1 taken 313 times.
2504 for(int32_t i=0; i<ZC_MIDI_COUNT; i++)
8221 {
8222 2191 tunes[i].data = load_midi(midis[i]);
8223
1/2
✓ Branch 0 taken 2191 times.
✗ Branch 1 not taken.
2191 if (!tunes[i].data)
8224 Z_error_fatal("Missing required file %s\n", midis[i]);
8225 2191 }
8226
8227
2/2
✓ Branch 0 taken 78876 times.
✓ Branch 1 taken 313 times.
79189 for(int32_t j=0; j<MAXCUSTOMMIDIS; j++)
8228 78876 tunes[ZC_MIDI_COUNT+j].data=NULL;
8229
8230 313 master_volume(digi_volume,midi_volume);
8231 313 }
8232
8233 // returns number of voices currently allocated
8234 int32_t sfx_count()
8235 {
8236 int32_t c=0;
8237
8238 for(int32_t i=0; i<WAV_COUNT; i++)
8239 if(sfx_voice[i]!=-1)
8240 ++c;
8241
8242 return c;
8243 }
8244
8245 // clean up finished samples
8246 18311193 void sfx_cleanup()
8247 {
8248
2/2
✓ Branch 0 taken 4687665408 times.
✓ Branch 1 taken 18311193 times.
4705976601 for(int32_t i=0; i<WAV_COUNT; i++)
8249
3/4
✓ Branch 0 taken 1267262 times.
✓ Branch 1 taken 4686398146 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267262 times.
4688932670 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
8250 {
8251 1267262 deallocate_voice(sfx_voice[i]);
8252 1267262 sfx_voice[i]=-1;
8253 1267262 }
8254 18311193 }
8255
8256 1267427 SAMPLE* sfx_get_sample(int32_t index)
8257 {
8258 // check index
8259
2/4
✓ Branch 0 taken 1267427 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1267427 times.
1267427 if (index<=0 || index>=WAV_COUNT)
8260 return nullptr;
8261
8262
2/2
✓ Branch 0 taken 446247 times.
✓ Branch 1 taken 821180 times.
1267427 if (sfxdat)
8263 {
8264
1/2
✓ Branch 0 taken 446247 times.
✗ Branch 1 not taken.
446247 if (index<Z35)
8265 {
8266 446247 return (SAMPLE*)sfxdata[index].dat;
8267 }
8268 else
8269 {
8270 return (SAMPLE*)sfxdata[Z35].dat;
8271 }
8272 }
8273 else
8274 {
8275 821180 return &customsfxdata[index];
8276 }
8277
8278 return nullptr;
8279 1267427 }
8280
8281 // allocates a voice for the sample "wav_index" (index into zelda.dat)
8282 // if a voice is already allocated (and/or playing), then it just returns true
8283 // Returns true: voice is allocated
8284 // false: unsuccessful
8285 1880839 bool sfx_init(int32_t index)
8286 {
8287 // check index
8288
3/4
✓ Branch 0 taken 1400147 times.
✓ Branch 1 taken 480692 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1400147 times.
1880839 if(index<=0 || index>=WAV_COUNT)
8289 480692 return false;
8290
8291
2/2
✓ Branch 0 taken 132780 times.
✓ Branch 1 taken 1267367 times.
1400147 if (sfx_voice[index] == -1)
8292 {
8293 1267367 SAMPLE* sample = sfx_get_sample(index);
8294
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1267367 times.
1267367 if (!sample)
8295 return false;
8296
8297 1267367 sfx_voice[index] = allocate_voice(sample);
8298 1267367 }
8299
8300 1400147 return sfx_voice[index] != -1;
8301 1880839 }
8302
8303 int32_t sfx_get_default_freq(int32_t index)
8304 {
8305 if (sfxdat)
8306 {
8307 if (index < Z35)
8308 {
8309 return ((SAMPLE*)sfxdata[index].dat)->freq;
8310 }
8311 else
8312 {
8313 return ((SAMPLE*)sfxdata[Z35].dat)->freq;
8314 }
8315 }
8316 else
8317 {
8318 return customsfxdata[index].freq;
8319 }
8320 }
8321
8322 int32_t sfx_get_length(int32_t index)
8323 {
8324 if (sfxdat)
8325 {
8326 if (index < Z35)
8327 {
8328 return int32_t(((SAMPLE*)sfxdata[index].dat)->len);
8329 }
8330 else
8331 {
8332 return int32_t(((SAMPLE*)sfxdata[Z35].dat)->len);
8333 }
8334 }
8335 else
8336 {
8337 return int32_t(customsfxdata[index].len);
8338 }
8339 }
8340
8341 // plays an sfx sample
8342 1880839 void sfx(int32_t index,int32_t pan,bool loop, bool restart, int32_t vol, int32_t freq)
8343 {
8344
2/2
✓ Branch 0 taken 1400147 times.
✓ Branch 1 taken 480692 times.
1880839 if(!sfx_init(index))
8345 480692 return;
8346
1/2
✓ Branch 0 taken 1400147 times.
✗ Branch 1 not taken.
1400147 if (!is_headless())
8347 {
8348 voice_set_playmode(sfx_voice[index], loop ? PLAYMODE_LOOP : PLAYMODE_PLAY);
8349 voice_set_pan(sfx_voice[index], pan);
8350
8351 // Only used by ZScript currently
8352 if (freq <= -1)
8353 {
8354 freq = sfx_get_default_freq(index);
8355 }
8356 voice_set_frequency(sfx_voice[index], freq);
8357
8358 // Only used by ZScript currently
8359 int32_t temp_volume = (sfx_volume * vol) / 10000 / 100;
8360 if (GameLoaded && !get_qr(qr_OLD_SCRIPT_VOLUME))
8361 temp_volume = (temp_volume * FFCore.usr_sfx_volume) / 10000 / 100;
8362 voice_set_volume(sfx_voice[index], temp_volume);
8363
8364 int32_t pos = voice_get_position(sfx_voice[index]);
8365
8366 if (restart) voice_set_position(sfx_voice[index], 0);
8367
8368 if (pos <= 0)
8369 voice_start(sfx_voice[index]);
8370 }
8371
8372
3/4
✓ Branch 0 taken 865732 times.
✓ Branch 1 taken 534415 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 865732 times.
1400147 if (restart && replay_is_debug())
8373 {
8374 // TODO(replays): get rid of this bandaid next time replays are mass-updated.
8375 865732 const char* sfx_name = sfx_string[index];
8376
2/2
✓ Branch 0 taken 853932 times.
✓ Branch 1 taken 11800 times.
865732 if (strcmp(sfx_name, "Hero is hit") == 0)
8377 11800 sfx_name = "Player is hit";
8378
2/2
✓ Branch 0 taken 853805 times.
✓ Branch 1 taken 127 times.
853932 else if (strcmp(sfx_name, "Hero dies") == 0)
8379 127 sfx_name = "Player dies";
8380
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 865732 times.
865732 replay_step_comment(fmt::format("sfx {}", sfx_name));
8381 865732 }
8382 1880839 }
8383
8384 // true if sfx is allocated
8385 203255 bool sfx_allocated(int32_t index)
8386 {
8387
3/4
✓ Branch 0 taken 33546 times.
✓ Branch 1 taken 169709 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 33546 times.
203255 return (index>0 && index<WAV_COUNT && sfx_voice[index]!=-1);
8388 }
8389
8390 // start it (in loop mode) if it's not already playing,
8391 // otherwise adjust it to play in loop mode -DD
8392 118478 void cont_sfx(int32_t index)
8393 {
8394
1/2
✓ Branch 0 taken 118478 times.
✗ Branch 1 not taken.
118478 if (is_headless())
8395 118478 return;
8396
8397 if(!sfx_init(index))
8398 {
8399 return;
8400 }
8401
8402 if(voice_get_position(sfx_voice[index])<=0)
8403 {
8404 voice_set_position(sfx_voice[index],0);
8405 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
8406 voice_set_volume(sfx_voice[index], sfx_volume);
8407 voice_start(sfx_voice[index]);
8408 }
8409 else
8410 {
8411 adjust_sfx(index, 128, true);
8412 }
8413 118478 }
8414
8415 // adjust parameters while playing
8416 4948 void adjust_sfx(int32_t index,int32_t pan,bool loop)
8417 {
8418
4/6
✓ Branch 0 taken 4511 times.
✓ Branch 1 taken 437 times.
✓ Branch 2 taken 4511 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 4511 times.
4948 if(index<=0 || index>=WAV_COUNT || sfx_voice[index]==-1)
8419 4948 return;
8420
8421 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
8422 voice_set_pan(sfx_voice[index],pan);
8423 4948 }
8424
8425 // pauses a voice
8426 3254 void pause_sfx(int32_t index)
8427 {
8428
3/6
✓ Branch 0 taken 3254 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 3254 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✓ Branch 5 taken 3254 times.
3254 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8429 voice_stop(sfx_voice[index]);
8430 3254 }
8431
8432 // resumes a voice
8433 1372 void resume_sfx(int32_t index)
8434 {
8435
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1372 times.
1372 if (is_headless())
8436 1372 return;
8437
8438 if(index>0 && index<WAV_COUNT && sfx_voice[index]!=-1)
8439 voice_start(sfx_voice[index]);
8440 1372 }
8441
8442 // pauses all active voices
8443 1063 void pause_all_sfx()
8444 {
8445
2/2
✓ Branch 0 taken 272128 times.
✓ Branch 1 taken 1063 times.
273191 for(int32_t i=0; i<WAV_COUNT; i++)
8446
2/2
✓ Branch 0 taken 272126 times.
✓ Branch 1 taken 2 times.
272130 if(sfx_voice[i]!=-1)
8447 2 voice_stop(sfx_voice[i]);
8448 1063 }
8449
8450 // resumes all paused voices
8451 1017 void resume_all_sfx()
8452 {
8453
2/2
✓ Branch 0 taken 260352 times.
✓ Branch 1 taken 1017 times.
261369 for(int32_t i=0; i<WAV_COUNT; i++)
8454
1/2
✓ Branch 0 taken 260352 times.
✗ Branch 1 not taken.
260352 if(sfx_voice[i]!=-1)
8455 voice_start(sfx_voice[i]);
8456 1017 }
8457
8458 // stops an sfx and deallocates the voice
8459 14618908 void stop_sfx(int32_t index)
8460 {
8461
3/4
✓ Branch 0 taken 14371862 times.
✓ Branch 1 taken 247046 times.
✓ Branch 2 taken 14371862 times.
✗ Branch 3 not taken.
14618908 if(index<=0 || index>=WAV_COUNT)
8462 247046 return;
8463
8464
2/2
✓ Branch 0 taken 47 times.
✓ Branch 1 taken 14371815 times.
14371862 if(sfx_voice[index]!=-1)
8465 {
8466 47 deallocate_voice(sfx_voice[index]);
8467 47 sfx_voice[index]=-1;
8468 47 }
8469 14618908 }
8470
8471 // Stops SFX played by Hero's item of the given family
8472 163371 void stop_item_sfx(int32_t family)
8473 {
8474 163371 int32_t id=current_item_id(family);
8475
8476
2/2
✓ Branch 0 taken 162269 times.
✓ Branch 1 taken 1102 times.
163371 if(id<0)
8477 162269 return;
8478
8479 1102 stop_sfx(itemsbuf[id].usesound);
8480 163371 }
8481
8482 9357 void kill_sfx()
8483 {
8484
2/2
✓ Branch 0 taken 2395392 times.
✓ Branch 1 taken 9357 times.
2404749 for(int32_t i=0; i<WAV_COUNT; i++)
8485
2/2
✓ Branch 0 taken 2395334 times.
✓ Branch 1 taken 58 times.
2395450 if(sfx_voice[i]!=-1)
8486 {
8487 58 deallocate_voice(sfx_voice[i]);
8488 58 sfx_voice[i]=-1;
8489 58 }
8490 9357 }
8491
8492 // TODO: when far out of bounds, sounds should dampen. currently we only pan.
8493 1201025 int32_t pan(int32_t x)
8494 {
8495
1/5
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 1201025 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1201025 switch(pan_style)
8496 {
8497 // MONO
8498 case 0:
8499 return 128;
8500
8501 // 1/2
8502 case 1:
8503 1201025 x -= viewport.x;
8504 1201025 return vbound((x>>1)+68,0,255);
8505
8506 // 3/4
8507 case 2:
8508 x -= viewport.x;
8509 return vbound(((x*3)>>2)+36,0,255);
8510
8511 // FULL
8512 case 3:
8513 default:
8514 x -= viewport.x;
8515 return vbound(x,0,255);
8516 }
8517 1201025 }
8518
8519 50408176 bool joybtn(int32_t b)
8520 {
8521
1/2
✓ Branch 0 taken 50408176 times.
✗ Branch 1 not taken.
50408176 if(b == 0)
8522 return false;
8523
1/2
✓ Branch 0 taken 50408176 times.
✗ Branch 1 not taken.
50408176 if (b-1 >= joy[joystick_index].num_buttons)
8524 50408176 return false;
8525
8526 return joy[joystick_index].button[b-1].b !=0;
8527 50408176 }
8528
8529 bool joystick(int32_t s)
8530 {
8531 if(s < 0)
8532 return false;
8533 if (s >= joy[joystick_index].num_sticks)
8534 return false;
8535
8536 for (int i = 0; i < joy[joystick_index].stick[s].num_axis; i++)
8537 {
8538 if (joy[joystick_index].stick[s].axis[i].d1 || joy[joystick_index].stick[s].axis[i].d2)
8539 return true;
8540 }
8541 return false;
8542 }
8543
8544 const char* joybtn_name(int32_t b)
8545 {
8546 if (b <= 0 || b > joy[joystick_index].num_buttons)
8547 return "";
8548
8549 return joy[joystick_index].button[b-1].name;
8550 }
8551
8552 const char* joystick_name(int32_t s)
8553 {
8554 if (s < 0 || s >= joy[joystick_index].num_sticks)
8555 return "";
8556
8557 return joy[joystick_index].stick[s].name;
8558 }
8559
8560 int32_t button_pressed()
8561 {
8562 if (joystick_index >= MAX_JOYSTICKS)
8563 return 0;
8564
8565 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8566 {
8567 if(joybtn(i))
8568 return i;
8569 }
8570
8571 return 0;
8572 }
8573
8574 int32_t next_press_key();
8575
8576 int32_t next_joy_input(bool buttons)
8577 {
8578 clear_keybuf();
8579
8580 //first, we need to wait until they're pressing no buttons
8581 for(;;)
8582 {
8583 if(keypressed())
8584 {
8585 switch(readkey()>>8)
8586 {
8587 case KEY_ESC:
8588 return -1;
8589
8590 case KEY_SPACE:
8591 return 0;
8592 }
8593 }
8594
8595 poll_joystick();
8596 bool done = true;
8597
8598 if (buttons)
8599 {
8600 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8601 {
8602 if(joybtn(i)) done = false;
8603 }
8604 }
8605 else
8606 {
8607 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8608 {
8609 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8610 return -2;
8611 }
8612 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8613 {
8614 if(joystick(i)) done = false;
8615 }
8616 }
8617
8618 if(done) break;
8619 rest(1);
8620 }
8621
8622 //now, we need to wait for them to press any button
8623 for(;;)
8624 {
8625 if(keypressed())
8626 {
8627 switch(readkey()>>8)
8628 {
8629 case KEY_ESC:
8630 return -1;
8631
8632 case KEY_SPACE:
8633 return 0;
8634 }
8635 }
8636
8637 poll_joystick();
8638
8639 if (buttons)
8640 {
8641 if (!gamepad_dlg_cur_joystick || !al_get_joystick_active(gamepad_dlg_cur_joystick))
8642 {
8643 InfoDialog("ZC", "Invalid gamepad. Did it disconnect?").show();
8644 return -2;
8645 }
8646 for(int32_t i=1; i<=joy[joystick_index].num_buttons; i++)
8647 {
8648 if(joybtn(i))
8649 return i;
8650 }
8651 }
8652 else
8653 {
8654 for(int32_t i=0; i<joy[joystick_index].num_sticks; i++)
8655 {
8656 if(joystick(i))
8657 return i;
8658 }
8659 }
8660 rest(1);
8661 }
8662 }
8663
8664 7853012 static bool rButton(bool &btn, bool &flag, bool rawbtn)
8665 {
8666
2/2
✓ Branch 0 taken 7824635 times.
✓ Branch 1 taken 28377 times.
7853012 bool ret = btn && !flag;
8667 7853012 flag = rawbtn;
8668
8669 7853012 return ret;
8670 }
8671 376913088 static bool rButton(bool &btn, bool &flag)
8672 {
8673
2/2
✓ Branch 0 taken 362997090 times.
✓ Branch 1 taken 13915998 times.
376913088 bool ret = btn && !flag;
8674 376913088 flag = btn;
8675
8676 376913088 return ret;
8677 }
8678 4643423 static bool rButtonPeek(bool btn, bool flag)
8679 {
8680
2/2
✓ Branch 0 taken 4296162 times.
✓ Branch 1 taken 347261 times.
4643423 if(!btn)
8681 {
8682 4296162 return false;
8683 }
8684
2/2
✓ Branch 0 taken 33613 times.
✓ Branch 1 taken 313648 times.
347261 else if(!flag)
8685 {
8686 33613 return true;
8687 }
8688
8689 313648 return false;
8690 4643423 }
8691
8692 // Updated only by keyboard/gamepad.
8693 // If in replay mode, this is set directly by the replay system.
8694 // This should never be read from directly - use control_state instead.
8695 bool raw_control_state[ZC_CONTROL_STATES];
8696
8697 // Every call to load_control_state (pretty much every frame) resets this to be equal to raw_control_state.
8698 // This state can drift from raw_control_state if button states are "eaten" or overriden by a script. But that only
8699 // lasts until the next call to load_control_state.
8700 bool control_state[ZC_CONTROL_STATES];
8701 bool disable_control[ZC_CONTROL_STATES];
8702 bool drunk_toggle_state[11];
8703 bool disabledKeys[127];
8704 bool KeyInput[127];
8705 bool KeyPress[127];
8706
8707 bool key_current_frame[127];
8708 bool key_previous_frame[127];
8709
8710 static bool key_system[127];
8711 static bool key_system_previous[127];
8712 static bool key_system_press[127];
8713
8714 bool button_press[ZC_CONTROL_STATES];
8715 bool button_hold[ZC_CONTROL_STATES];
8716
8717 #define STICK_1_X joy[joystick_index].stick[js_stick_1_x_stick].axis[js_stick_1_x_axis]
8718 #define STICK_1_Y joy[joystick_index].stick[js_stick_1_y_stick].axis[js_stick_1_y_axis]
8719 #define STICK_2_X joy[joystick_index].stick[js_stick_2_x_stick].axis[js_stick_2_x_axis]
8720 #define STICK_2_Y joy[joystick_index].stick[js_stick_2_y_stick].axis[js_stick_2_y_axis]
8721 #define STICK_PRECISION 56 //define your own sensitivity
8722
8723 15664553 void load_control_state()
8724 {
8725 15664553 load_control_called_this_frame = true;
8726
8727
2/2
✓ Branch 0 taken 12461491 times.
✓ Branch 1 taken 3203062 times.
15664553 if (replay_version_check(8, 11))
8728 {
8729
2/2
✓ Branch 0 taken 57655116 times.
✓ Branch 1 taken 3203062 times.
60858178 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8730 57655116 down_control_states[i] = raw_control_state[i];
8731 3203062 }
8732
8733
2/2
✓ Branch 0 taken 15664532 times.
✓ Branch 1 taken 21 times.
15664553 if (!replay_is_replaying())
8734 {
8735
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[0]=zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset < -STICK_PRECISION : joybtn(DUbtn));
8736
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[1]=zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn));
8737
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[2]=zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn));
8738
3/6
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 21 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 21 times.
✗ Branch 5 not taken.
21 raw_control_state[3]=zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn));
8739
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[4]=zc_getrawkey(Akey, true)||joybtn(Abtn);
8740
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[5]=zc_getrawkey(Bkey, true)||joybtn(Bbtn);
8741
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[6]=zc_getrawkey(Skey, true)||joybtn(Sbtn);
8742
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[7]=zc_getrawkey(Lkey, true)||joybtn(Lbtn);
8743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[8]=zc_getrawkey(Rkey, true)||joybtn(Rbtn);
8744
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[9]=zc_getrawkey(Pkey, true)||joybtn(Pbtn);
8745
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[10]=zc_getrawkey(Exkey1, true)||joybtn(Exbtn1);
8746
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[11]=zc_getrawkey(Exkey2, true)||joybtn(Exbtn2);
8747
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[12]=zc_getrawkey(Exkey3, true)||joybtn(Exbtn3);
8748
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 21 times.
21 raw_control_state[13]=zc_getrawkey(Exkey4, true)||joybtn(Exbtn4);
8749
8750
1/2
✓ Branch 0 taken 21 times.
✗ Branch 1 not taken.
21 if(num_joysticks != 0)
8751 {
8752 raw_control_state[14] = STICK_2_Y.pos - js_stick_2_y_offset < -STICK_PRECISION;
8753 raw_control_state[15] = STICK_2_Y.pos - js_stick_2_y_offset > STICK_PRECISION;
8754 raw_control_state[16] = STICK_2_X.pos - js_stick_2_x_offset < -STICK_PRECISION;
8755 raw_control_state[17] = STICK_2_X.pos - js_stick_2_x_offset > STICK_PRECISION;
8756 }
8757 else
8758 {
8759 21 raw_control_state[14] = false;
8760 21 raw_control_state[15] = false;
8761 21 raw_control_state[16] = false;
8762 21 raw_control_state[17] = false;
8763 }
8764 21 }
8765
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 15664548 times.
15664553 if (replay_is_active())
8766 {
8767
2/2
✓ Branch 0 taken 1211700 times.
✓ Branch 1 taken 14452848 times.
15664548 if (replay_get_version() < 3)
8768 1211700 replay_poll();
8769
4/4
✓ Branch 0 taken 14452827 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 12691452 times.
✓ Branch 3 taken 1761375 times.
14452848 else if (replay_is_replaying() && replay_get_version() < 6)
8770 1761375 replay_peek_input();
8771
4/4
✓ Branch 0 taken 12691452 times.
✓ Branch 1 taken 21 times.
✓ Branch 2 taken 9488390 times.
✓ Branch 3 taken 3203062 times.
12691473 else if (replay_is_replaying() && replay_version_check(8, 11))
8772 3203062 replay_peek_input();
8773
2/2
✓ Branch 0 taken 14324606 times.
✓ Branch 1 taken 1339942 times.
15664548 if (replay_get_version() == 8)
8774 1339942 update_keys();
8775 15664548 }
8776
8777 // Some test replay files were made before a serious input bug was fixed, so instead
8778 // of re-doing them or tossing them out, just check for that zplay version.
8779
3/4
✓ Branch 0 taken 15664543 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 121900 times.
✓ Branch 3 taken 15542643 times.
15664553 bool botched_input = replay_is_active() && replay_get_version() != 1 && replay_get_version() < 8;
8780
2/2
✓ Branch 0 taken 281961774 times.
✓ Branch 1 taken 15664543 times.
297626317 for (int i = 0; i < ZC_CONTROL_STATES; i++)
8781 {
8782 281961774 control_state[i] = raw_control_state[i];
8783
4/4
✓ Branch 0 taken 53024004 times.
✓ Branch 1 taken 228937770 times.
✓ Branch 2 taken 2611994 times.
✓ Branch 3 taken 50412010 times.
281961774 if (botched_input && !control_state[i])
8784 50412010 down_control_states[i] = false;
8785 281961774 }
8786 15664543 bool did_bad_cutscene_btn = false;
8787
2/2
✓ Branch 0 taken 15664543 times.
✓ Branch 1 taken 281961774 times.
297626317 for(int q = 0; q < 18; ++q)
8788
4/4
✓ Branch 0 taken 13340665 times.
✓ Branch 1 taken 268621109 times.
✓ Branch 2 taken 13338954 times.
✓ Branch 3 taken 1711 times.
281963485 if(control_state[q] && !active_cutscene.can_button(q))
8789 {
8790 1711 control_state[q] = false;
8791 1711 did_bad_cutscene_btn = true;
8792 1711 }
8793
2/2
✓ Branch 0 taken 15663276 times.
✓ Branch 1 taken 1267 times.
15664543 if(did_bad_cutscene_btn)
8794 1267 active_cutscene.error();
8795
8796 15664543 button_press[0]=rButton(control_state[0],button_hold[0]);
8797 15664543 button_press[1]=rButton(control_state[1],button_hold[1]);
8798 15664543 button_press[2]=rButton(control_state[2],button_hold[2]);
8799 15664543 button_press[3]=rButton(control_state[3],button_hold[3]);
8800 15664543 button_press[4]=rButton(control_state[4],button_hold[4]);
8801 15664543 button_press[5]=rButton(control_state[5],button_hold[5]);
8802 15664543 button_press[6]=rButton(control_state[6],button_hold[6]);
8803 15664543 button_press[7]=rButton(control_state[7],button_hold[7]);
8804 15664543 button_press[8]=rButton(control_state[8],button_hold[8]);
8805 15664543 button_press[9]=rButton(control_state[9],button_hold[9]);
8806 15664543 button_press[10]=rButton(control_state[10],button_hold[10]);
8807 15664543 button_press[11]=rButton(control_state[11],button_hold[11]);
8808 15664543 button_press[12]=rButton(control_state[12],button_hold[12]);
8809 15664543 button_press[13]=rButton(control_state[13],button_hold[13]);
8810 15664543 button_press[14]=rButton(control_state[14],button_hold[14]);
8811 15664543 button_press[15]=rButton(control_state[15],button_hold[15]);
8812 15664543 button_press[16]=rButton(control_state[16],button_hold[16]);
8813 15664543 button_press[17]=rButton(control_state[17],button_hold[17]);
8814 15664543 }
8815
8816 // Returns true if any game key is pressed. This is needed because keypressed()
8817 // doesn't detect modifier keys and control_state[] can be modified by scripts.
8818 78785999 bool zc_key_pressed()
8819 //may also need to use zc_getrawkey
8820 {
8821
7/10
✓ Branch 0 taken 63631993 times.
✓ Branch 1 taken 15154006 times.
✓ Branch 2 taken 15154006 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 15154006 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 12418197 times.
✓ Branch 7 taken 12418197 times.
✗ Branch 8 not taken.
✓ Branch 9 taken 4960120 times.
83746119 if((zc_getrawkey(DUkey, true)||(analog_movement ? STICK_1_Y.d1 || STICK_1_Y.pos - js_stick_1_y_offset< -STICK_PRECISION : joybtn(DUbtn))) ||
8822
4/6
✓ Branch 0 taken 12418197 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 12418197 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9454594 times.
✓ Branch 5 taken 9454594 times.
12418197 (zc_getrawkey(DDkey, true)||(analog_movement ? STICK_1_Y.d2 || STICK_1_Y.pos - js_stick_1_y_offset > STICK_PRECISION : joybtn(DDbtn))) ||
8823
4/6
✓ Branch 0 taken 9454594 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9454594 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 6256717 times.
✓ Branch 5 taken 6256717 times.
9454594 (zc_getrawkey(DLkey, true)||(analog_movement ? STICK_1_X.d1 || STICK_1_X.pos - js_stick_1_x_offset < -STICK_PRECISION : joybtn(DLbtn))) ||
8824
4/6
✓ Branch 0 taken 6256717 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6256717 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 5369386 times.
✓ Branch 5 taken 5369386 times.
6256717 (zc_getrawkey(DRkey, true)||(analog_movement ? STICK_1_X.d2 || STICK_1_X.pos - js_stick_1_x_offset > STICK_PRECISION : joybtn(DRbtn))) ||
8825
1/2
✓ Branch 0 taken 5369386 times.
✗ Branch 1 not taken.
5369386 (zc_getrawkey(Akey, true)||joybtn(Abtn)) ||
8826
3/4
✓ Branch 0 taken 5182086 times.
✓ Branch 1 taken 187300 times.
✓ Branch 2 taken 5182086 times.
✗ Branch 3 not taken.
5369386 (zc_getrawkey(Bkey, true)||joybtn(Bbtn)) ||
8827
3/4
✓ Branch 0 taken 5035153 times.
✓ Branch 1 taken 146933 times.
✓ Branch 2 taken 5035153 times.
✗ Branch 3 not taken.
5182086 (zc_getrawkey(Skey, true)||joybtn(Sbtn)) ||
8828
3/4
✓ Branch 0 taken 5012936 times.
✓ Branch 1 taken 22217 times.
✓ Branch 2 taken 5012936 times.
✗ Branch 3 not taken.
5035153 (zc_getrawkey(Lkey, true)||joybtn(Lbtn)) ||
8829
3/4
✓ Branch 0 taken 4986567 times.
✓ Branch 1 taken 26369 times.
✓ Branch 2 taken 4986567 times.
✗ Branch 3 not taken.
5012936 (zc_getrawkey(Rkey, true)||joybtn(Rbtn)) ||
8830
3/4
✓ Branch 0 taken 4979282 times.
✓ Branch 1 taken 7285 times.
✓ Branch 2 taken 4979282 times.
✗ Branch 3 not taken.
4986567 (zc_getrawkey(Pkey, true)||joybtn(Pbtn)) ||
8831
3/4
✓ Branch 0 taken 4962043 times.
✓ Branch 1 taken 17239 times.
✓ Branch 2 taken 4962043 times.
✗ Branch 3 not taken.
4979282 (zc_getrawkey(Exkey1, true)||joybtn(Exbtn1)) ||
8832
3/4
✓ Branch 0 taken 4960214 times.
✓ Branch 1 taken 1829 times.
✓ Branch 2 taken 4960214 times.
✗ Branch 3 not taken.
4962043 (zc_getrawkey(Exkey2, true)||joybtn(Exbtn2)) ||
8833
3/4
✓ Branch 0 taken 4960179 times.
✓ Branch 1 taken 35 times.
✓ Branch 2 taken 4960179 times.
✗ Branch 3 not taken.
4960214 (zc_getrawkey(Exkey3, true)||joybtn(Exbtn3)) ||
8834
2/2
✓ Branch 0 taken 4960120 times.
✓ Branch 1 taken 59 times.
4960179 (zc_getrawkey(Exkey4, true)||joybtn(Exbtn4))) // Skipping joystick axes
8835 140823667 return true;
8836
8837 4960120 return false;
8838 18519801 }
8839
8840 299949789 bool getInput(int32_t btn, int input_flags)
8841 {
8842
3/4
✓ Branch 0 taken 267055517 times.
✓ Branch 1 taken 32894272 times.
✓ Branch 2 taken 267055517 times.
✗ Branch 3 not taken.
299949789 if((input_flags & INPUT_HERO_ACTION) && Hero.no_control())
8843 return false;
8844
8845 299949789 bool press = input_flags & INPUT_PRESS;
8846 299949789 bool drunk = input_flags & INPUT_DRUNK;
8847 299949789 bool ignoreDisable = input_flags & INPUT_IGNORE_DISABLE;
8848 299949789 bool eatEntirely = input_flags & INPUT_EAT_ENTIRELY;
8849 299949789 bool peek = input_flags & INPUT_PEEK;
8850
8851 299949789 bool ret = false, drunkstate = false, rawret = false;;
8852 299949789 bool* flag = &down_control_states[btn];
8853
2/7
✓ Branch 0 taken 281411081 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✓ Branch 6 taken 18538708 times.
299949789 switch(btn)
8854 {
8855 case btnF12:
8856 ret = zc_getkey(KEY_F12, ignoreDisable);
8857 rawret = zc_getrawkey(KEY_F12, ignoreDisable);
8858 eatEntirely = false;
8859 break;
8860 case btnF11:
8861 ret = zc_getkey(KEY_F11, ignoreDisable);
8862 rawret = zc_getrawkey(KEY_F11, ignoreDisable);
8863 eatEntirely = false;
8864 break;
8865 case btnF5:
8866 ret = zc_getkey(KEY_F5, ignoreDisable);
8867 rawret = zc_getrawkey(KEY_F5, ignoreDisable);
8868 eatEntirely = false;
8869 break;
8870 case btnQ:
8871 ret = zc_getkey(KEY_Q, ignoreDisable);
8872 rawret = zc_getrawkey(KEY_Q, ignoreDisable);
8873 eatEntirely = false;
8874 break;
8875 case btnI:
8876 ret = zc_getkey(KEY_I, ignoreDisable);
8877 rawret = zc_getrawkey(KEY_I, ignoreDisable);
8878 eatEntirely = false;
8879 break;
8880 case btnM:
8881
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18538708 times.
18538708 if(FFCore.kb_typing_mode) return false;
8882 18538708 rawret = ret = zc_getrawkey(KEY_ESC, ignoreDisable);
8883 18538708 eatEntirely = false;
8884 18538708 break;
8885 default: //control_state[] index
8886
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 281411081 times.
281411081 if(FFCore.kb_typing_mode) return false;
8887
6/6
✓ Branch 0 taken 280031667 times.
✓ Branch 1 taken 1379414 times.
✓ Branch 2 taken 18073746 times.
✓ Branch 3 taken 261957921 times.
✓ Branch 4 taken 18070773 times.
✓ Branch 5 taken 2973 times.
281411081 if(!ignoreDisable && get_qr(qr_FIXDRUNKINPUTS) && disable_control[btn]) drunk = false;
8888
2/2
✓ Branch 0 taken 15930325 times.
✓ Branch 1 taken 265477783 times.
281408108 else if(btn<11) drunkstate = drunk_toggle_state[btn];
8889
4/4
✓ Branch 0 taken 250110087 times.
✓ Branch 1 taken 31300994 times.
✓ Branch 2 taken 7136 times.
✓ Branch 3 taken 31293858 times.
312712075 ret = control_state[btn] && (ignoreDisable || !disable_control[btn]);
8890 281411081 rawret = raw_control_state[btn];
8891 281411081 }
8892
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 299949789 times.
299949789 assert(flag);
8893
2/2
✓ Branch 0 taken 192502040 times.
✓ Branch 1 taken 107447749 times.
299949789 if(press)
8894 {
8895
2/2
✓ Branch 0 taken 4643423 times.
✓ Branch 1 taken 102804326 times.
107447749 if(peek)
8896 4643423 ret = rButtonPeek(ret, *flag);
8897
2/2
✓ Branch 0 taken 94951314 times.
✓ Branch 1 taken 7853012 times.
102804326 else if(get_qr(qr_BROKEN_INPUT_DOWN_STATE)) ret = rButton(ret, *flag);
8898 7853012 else ret = rButton(ret, *flag, rawret);
8899 107447749 }
8900
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 299949789 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
299949789 if(eatEntirely && ret) control_state[btn] = false;
8901
4/4
✓ Branch 0 taken 224466251 times.
✓ Branch 1 taken 75483538 times.
✓ Branch 2 taken 224466170 times.
✓ Branch 3 taken 81 times.
299949789 if(drunk && drunkstate) ret = !ret;
8902 299949789 return ret;
8903 299949789 }
8904
8905 15041733 byte getIntBtnInput(byte intbtn, int input_flags)
8906 {
8907 15041733 byte ret = 0;
8908
2/2
✓ Branch 0 taken 10620570 times.
✓ Branch 1 taken 4421163 times.
15041733 if(intbtn & INT_BTN_A) ret |= getInput(btnA, input_flags) ? INT_BTN_A : 0;
8909
2/2
✓ Branch 0 taken 14832767 times.
✓ Branch 1 taken 208966 times.
15041733 if(intbtn & INT_BTN_B) ret |= getInput(btnB, input_flags) ? INT_BTN_B : 0;
8910
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_L) ret |= getInput(btnL, input_flags) ? INT_BTN_L : 0;
8911
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_R) ret |= getInput(btnR, input_flags) ? INT_BTN_R : 0;
8912
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_EX1) ret |= getInput(btnEx1, input_flags) ? INT_BTN_EX1 : 0;
8913
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_EX2) ret |= getInput(btnEx2, input_flags) ? INT_BTN_EX2 : 0;
8914
2/2
✓ Branch 0 taken 14834085 times.
✓ Branch 1 taken 207648 times.
15041733 if(intbtn & INT_BTN_EX3) ret |= getInput(btnEx3, input_flags) ? INT_BTN_EX3 : 0;
8915
2/2
✓ Branch 0 taken 14833970 times.
✓ Branch 1 taken 207763 times.
15041733 if(intbtn & INT_BTN_EX4) ret |= getInput(btnEx4, input_flags) ? INT_BTN_EX4 : 0;
8916 15041733 return ret; //No early return, to make sure all button presses are eaten that should be! -Em
8917 }
8918
8919 7513 byte checkIntBtnVal(byte intbtn, byte vals)
8920 {
8921 7513 return intbtn&vals;
8922 }
8923
8924 208698 bool Up()
8925 {
8926 208698 return getInput(btnUp);
8927 }
8928 208697 bool Down()
8929 {
8930 208697 return getInput(btnDown);
8931 }
8932 208697 bool Left()
8933 {
8934 208697 return getInput(btnLeft);
8935 }
8936 208697 bool Right()
8937 {
8938 208697 return getInput(btnRight);
8939 }
8940 530261 bool cAbtn()
8941 {
8942 530261 return getInput(btnA);
8943 }
8944 3306494 bool cBbtn()
8945 {
8946 3306494 return getInput(btnB);
8947 }
8948 bool cSbtn()
8949 {
8950 return getInput(btnS);
8951 }
8952 208608 bool cLbtn()
8953 {
8954 208608 return getInput(btnL);
8955 }
8956 208608 bool cRbtn()
8957 {
8958 208608 return getInput(btnR);
8959 }
8960 bool cPbtn()
8961 {
8962 return getInput(btnP);
8963 }
8964 bool cEx1btn()
8965 {
8966 return getInput(btnEx1);
8967 }
8968 bool cEx2btn()
8969 {
8970 return getInput(btnEx2);
8971 }
8972 bool cEx3btn()
8973 {
8974 return getInput(btnEx3);
8975 }
8976 bool cEx4btn()
8977 {
8978 return getInput(btnEx4);
8979 }
8980 bool AxisUp()
8981 {
8982 return getInput(btnAxisUp);
8983 }
8984 bool AxisDown()
8985 {
8986 return getInput(btnAxisDown);
8987 }
8988 bool AxisLeft()
8989 {
8990 return getInput(btnAxisLeft);
8991 }
8992 bool AxisRight()
8993 {
8994 return getInput(btnAxisRight);
8995 }
8996
8997 bool cMbtn()
8998 {
8999 return getInput(btnM);
9000 }
9001 bool cF12()
9002 {
9003 return getInput(btnF12);
9004 }
9005 bool cF11()
9006 {
9007 return getInput(btnF11);
9008 }
9009 bool cF5()
9010 {
9011 return getInput(btnF5);
9012 }
9013 bool cQ()
9014 {
9015 return getInput(btnQ);
9016 }
9017 bool cI()
9018 {
9019 return getInput(btnI);
9020 }
9021
9022 211312 bool rUp()
9023 {
9024 211312 return getInput(btnUp, INPUT_PRESS);
9025 }
9026 211099 bool rDown()
9027 {
9028 211099 return getInput(btnDown, INPUT_PRESS);
9029 }
9030 210903 bool rLeft()
9031 {
9032 210903 return getInput(btnLeft, INPUT_PRESS);
9033 }
9034 210163 bool rRight()
9035 {
9036 210163 return getInput(btnRight, INPUT_PRESS);
9037 }
9038 4648 bool rAbtn()
9039 {
9040 4648 return getInput(btnA, INPUT_PRESS);
9041 }
9042 bool rBbtn()
9043 {
9044 return getInput(btnB, INPUT_PRESS);
9045 }
9046 210364 bool rSbtn()
9047 {
9048 210364 return getInput(btnS, INPUT_PRESS);
9049 }
9050 18519801 bool rMbtn()
9051 {
9052 18519801 return getInput(btnM, INPUT_PRESS);
9053 }
9054 186046 bool rLbtn()
9055 {
9056 186046 return getInput(btnL, INPUT_PRESS);
9057 }
9058 186041 bool rRbtn()
9059 {
9060 186041 return getInput(btnR, INPUT_PRESS);
9061 }
9062 208608 bool rPbtn()
9063 {
9064 208608 return getInput(btnP, INPUT_PRESS);
9065 }
9066 bool rEx1btn()
9067 {
9068 return getInput(btnEx1, INPUT_PRESS);
9069 }
9070 bool rEx2btn()
9071 {
9072 return getInput(btnEx2, INPUT_PRESS);
9073 }
9074 186037 bool rEx3btn()
9075 {
9076 186037 return getInput(btnEx3, INPUT_PRESS);
9077 }
9078 186037 bool rEx4btn()
9079 {
9080 186037 return getInput(btnEx4, INPUT_PRESS);
9081 }
9082 bool rAxisUp()
9083 {
9084 return getInput(btnAxisUp, INPUT_PRESS);
9085 }
9086 bool rAxisDown()
9087 {
9088 return getInput(btnAxisDown, INPUT_PRESS);
9089 }
9090 bool rAxisLeft()
9091 {
9092 return getInput(btnAxisLeft, INPUT_PRESS);
9093 }
9094 bool rAxisRight()
9095 {
9096 return getInput(btnAxisRight, INPUT_PRESS);
9097 }
9098
9099 bool rF11()
9100 {
9101 return getInput(btnF11, INPUT_PRESS);
9102 }
9103 bool rQ()
9104 {
9105 return getInput(btnQ, INPUT_PRESS);
9106 }
9107 bool rI()
9108 {
9109 return getInput(btnI, INPUT_PRESS);
9110 }
9111
9112 bool DrunkUp()
9113 {
9114 return getInput(btnUp, INPUT_DRUNK);
9115 }
9116 bool DrunkDown()
9117 {
9118 return getInput(btnDown, INPUT_DRUNK);
9119 }
9120 bool DrunkLeft()
9121 {
9122 return getInput(btnLeft, INPUT_DRUNK);
9123 }
9124 bool DrunkRight()
9125 {
9126 return getInput(btnRight, INPUT_DRUNK);
9127 }
9128 bool DrunkcAbtn()
9129 {
9130 return getInput(btnA, INPUT_DRUNK);
9131 }
9132 bool DrunkcBbtn()
9133 {
9134 return getInput(btnB, INPUT_DRUNK);
9135 }
9136 bool DrunkcEx1btn()
9137 {
9138 return getInput(btnEx1, INPUT_DRUNK);
9139 }
9140 bool DrunkcEx2btn()
9141 {
9142 return getInput(btnEx2, INPUT_DRUNK);
9143 }
9144 bool DrunkcSbtn()
9145 {
9146 return getInput(btnS, INPUT_DRUNK);
9147 }
9148 bool DrunkcMbtn()
9149 {
9150 return getInput(btnM, INPUT_DRUNK);
9151 }
9152 bool DrunkcLbtn()
9153 {
9154 return getInput(btnL, INPUT_DRUNK);
9155 }
9156 bool DrunkcRbtn()
9157 {
9158 return getInput(btnR, INPUT_DRUNK);
9159 }
9160 bool DrunkcPbtn()
9161 {
9162 return getInput(btnP, INPUT_DRUNK);
9163 }
9164
9165 bool DrunkrUp()
9166 {
9167 return getInput(btnUp, INPUT_PRESS | INPUT_DRUNK);
9168 }
9169 bool DrunkrDown()
9170 {
9171 return getInput(btnDown, INPUT_PRESS | INPUT_DRUNK);
9172 }
9173 bool DrunkrLeft()
9174 {
9175 return getInput(btnLeft, INPUT_PRESS | INPUT_DRUNK);
9176 }
9177 bool DrunkrRight()
9178 {
9179 return getInput(btnRight, INPUT_PRESS | INPUT_DRUNK);
9180 }
9181 bool DrunkrAbtn()
9182 {
9183 return getInput(btnA, INPUT_PRESS | INPUT_DRUNK);
9184 }
9185 bool DrunkrBbtn()
9186 {
9187 return getInput(btnB, INPUT_PRESS | INPUT_DRUNK);
9188 }
9189 bool DrunkrEx1btn()
9190 {
9191 return getInput(btnEx1, INPUT_PRESS | INPUT_DRUNK);
9192 }
9193 bool DrunkrEx2btn()
9194 {
9195 return getInput(btnEx2, INPUT_PRESS | INPUT_DRUNK);
9196 }
9197 bool DrunkrEx3btn()
9198 {
9199 return getInput(btnEx3, INPUT_PRESS | INPUT_DRUNK);
9200 }
9201 bool DrunkrEx4btn()
9202 {
9203 return getInput(btnEx4, INPUT_PRESS | INPUT_DRUNK);
9204 }
9205 bool DrunkrSbtn()
9206 {
9207 return getInput(btnS, INPUT_PRESS | INPUT_DRUNK);
9208 }
9209 bool DrunkrMbtn()
9210 {
9211 return getInput(btnM, INPUT_PRESS | INPUT_DRUNK);
9212 }
9213 bool DrunkrLbtn()
9214 {
9215 return getInput(btnL, INPUT_PRESS | INPUT_DRUNK);
9216 }
9217 bool DrunkrRbtn()
9218 {
9219 return getInput(btnR, INPUT_PRESS | INPUT_DRUNK);
9220 }
9221 bool DrunkrPbtn()
9222 {
9223 return getInput(btnP, INPUT_PRESS | INPUT_DRUNK);
9224 }
9225
9226 18907 void eat_buttons()
9227 {
9228 18907 getInput(btnA, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9229 18907 getInput(btnB, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9230 18907 getInput(btnS, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9231 18907 getInput(btnM, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9232 18907 getInput(btnL, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9233 18907 getInput(btnR, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9234 18907 getInput(btnP, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9235 18907 getInput(btnEx1, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9236 18907 getInput(btnEx2, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9237 18907 getInput(btnEx3, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9238 18907 getInput(btnEx4, INPUT_PRESS | INPUT_IGNORE_DISABLE);
9239 18907 }
9240
9241 // Is true for the _first frame_ of a key press.
9242 // But! it is possible that a script manually sets the value of KeyPress,
9243 // in which case it will be restored to the "true" value based on `key_current_frame`
9244 // and `key_previous_frame` on the next frame.
9245 46 bool zc_readkey(int32_t k, bool ignoreDisable)
9246 {
9247
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 if(ignoreDisable) return KeyPress[k];
9248
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 46 times.
46 switch(k)
9249 {
9250 case KEY_F7:
9251 case KEY_F8:
9252 case KEY_F9:
9253 return KeyPress[k];
9254
9255 default:
9256
1/2
✓ Branch 0 taken 46 times.
✗ Branch 1 not taken.
46 return KeyPress[k] && !disabledKeys[k];
9257 }
9258 46 }
9259
9260 // Is true for _every frame_ a key is held down.
9261 // But! it is possible that a script manually sets the value of KeyInput,
9262 // in which case it will be restored to the "true" value based on `key_current_frame`
9263 // on the next frame.
9264 bool zc_getkey(int32_t k, bool ignoreDisable)
9265 {
9266 if(ignoreDisable) return KeyInput[k];
9267 switch(k)
9268 {
9269 case KEY_F7:
9270 case KEY_F8:
9271 case KEY_F9:
9272 return KeyInput[k];
9273
9274 default:
9275 return KeyInput[k] && !disabledKeys[k];
9276 }
9277 }
9278
9279 // Reads (and then clears) the current frame key state directly.
9280 // Scripts can also modify `key_current_frame`.
9281 900 bool zc_readrawkey(int32_t k, bool ignoreDisable)
9282 {
9283
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 898 times.
900 if(zc_getrawkey(k, ignoreDisable))
9284 {
9285 2 _key[k]=key[k]=key_current_frame[k]=0;
9286 2 return true;
9287 }
9288 898 _key[k]=key[k]=key_current_frame[k]=0;
9289 898 return false;
9290 900 }
9291
9292 // Reads the current frame key state directly.
9293 // Scripts can also modify `key_current_frame`.
9294 125791063 bool zc_getrawkey(int32_t k, bool ignoreDisable)
9295 {
9296
2/2
✓ Branch 0 taken 107271170 times.
✓ Branch 1 taken 18519893 times.
125791063 if(ignoreDisable) return key_current_frame[k];
9297
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519893 times.
18519893 switch(k)
9298 {
9299 case KEY_F7:
9300 case KEY_F8:
9301 case KEY_F9:
9302 return key_current_frame[k];
9303
9304 default:
9305
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 18519893 times.
18519893 return key_current_frame[k] && !disabledKeys[k];
9306 }
9307 125791063 }
9308
9309 // Only used for a handful of keys, like tilde and Function keys.
9310 // This state is never read within the game.
9311 // It exists so that all keyboard input still functions during replay,
9312 // without inadvertently doing things like toggling throttling if the player
9313 // presses ~
9314 bool zc_get_system_key(int32_t k)
9315 {
9316 return key_system[k];
9317 }
9318
9319 // True for the _first_ frame of a key press.
9320 166678209 bool zc_read_system_key(int32_t k)
9321 {
9322 166678209 return key_system_press[k];
9323 }
9324
9325 2352014727 bool is_system_key(int32_t k)
9326 {
9327
2/2
✓ Branch 0 taken 2185336518 times.
✓ Branch 1 taken 166678209 times.
2352014727 switch (k)
9328 {
9329 case KEY_BACKQUOTE:
9330 case KEY_CLOSEBRACE:
9331 case KEY_END:
9332 case KEY_HOME:
9333 case KEY_OPENBRACE:
9334 case KEY_PGDN:
9335 case KEY_PGUP:
9336 case KEY_TAB:
9337 case KEY_TILDE:
9338 166678209 return true;
9339 }
9340 2185336518 return is_Fkey(k);
9341 2352014727 }
9342
9343 18519801 void update_system_keys()
9344 {
9345
2/2
✓ Branch 0 taken 2352014727 times.
✓ Branch 1 taken 18519801 times.
2370534528 for (int32_t q = 0; q < 127; ++q)
9346 {
9347
2/2
✓ Branch 0 taken 388915821 times.
✓ Branch 1 taken 1963098906 times.
2352014727 if (!is_system_key(q))
9348 1963098906 continue;
9349
9350 388915821 key_system[q] = key[q];
9351
1/2
✓ Branch 0 taken 388915821 times.
✗ Branch 1 not taken.
388915821 key_system_press[q] = key_system[q] && !key_system_previous[q];
9352 388915821 key_system_previous[q] = key_system[q];
9353 388915821 }
9354 18519801 }
9355
9356 19859743 void update_keys()
9357 {
9358
2/2
✓ Branch 0 taken 2522187361 times.
✓ Branch 1 taken 19859743 times.
2542047104 for (int32_t q = 0; q < 127; ++q)
9359 {
9360 // When replaying, replay.cpp takes care of updating `key_current_frame`.
9361
2/2
✓ Branch 0 taken 2522174661 times.
✓ Branch 1 taken 12700 times.
2522187361 if (!replay_is_replaying())
9362 12700 key_current_frame[q] = key[q];
9363
9364
2/2
✓ Branch 0 taken 2502802703 times.
✓ Branch 1 taken 19384658 times.
2522187361 KeyPress[q] = key_current_frame[q] && !key_previous_frame[q];
9365 2522187361 KeyInput[q] = key_current_frame[q];
9366 2522187361 key_previous_frame[q] = key_current_frame[q];
9367 2522187361 }
9368 19859743 }
9369
9370